Created
March 17, 2019 10:50
-
-
Save zacker330/7f96aa7a2aadad74c0bdec9f3f2ad602 to your computer and use it in GitHub Desktop.
[echo http server] #python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
def listen(): | |
connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
connection.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
connection.bind(('0.0.0.0', 5555)) | |
connection.listen(10) | |
while True: | |
current_connection, address = connection.accept() | |
while True: | |
data = current_connection.recv(2048) | |
if data == 'quit\r\n': | |
current_connection.shutdown(1) | |
current_connection.close() | |
break | |
elif data == 'stop\r\n': | |
current_connection.shutdown(1) | |
current_connection.close() | |
exit() | |
elif data: | |
current_connection.send(data) | |
print data | |
if __name__ == "__main__": | |
try: | |
listen() | |
except KeyboardInterrupt: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment