Last active
September 14, 2016 06:18
-
-
Save makersm/bf5860192341fac68a9248830d7f93f9 to your computer and use it in GitHub Desktop.
This file contains 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 | |
import subprocess | |
server_address = '/superpython' | |
if __name__ == '__main__': | |
# create socket | |
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | |
# Bind the socket to the port | |
print('starting up on {}...'.format(server_address)) | |
sock.bind(server_address) | |
# Listen for incoming connections | |
sock.listen(20) | |
while True: | |
# Wait for a connection | |
print('waiting for a connection...') | |
connection, client_address = sock.accept() | |
try: | |
# Receive the data in small chunks and retransmit it | |
tmp = list() | |
while True: | |
data = connection.recv(1024) | |
if data: | |
tmp.append(data) | |
else: | |
data_all = b''.join(tmp) | |
eval(data_all) | |
finally: | |
# Clean up the connection | |
connection.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment