Created
June 17, 2017 18:25
-
-
Save linuxoid69/e57c100f87a5b2faf89cf9825e989366 to your computer and use it in GitHub Desktop.
server socket
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
#!/usr/bin/env python | |
import socket | |
from socket import AF_INET, SOCK_STREAM | |
HOST = '' # Symbolic name meaning all available interfaces | |
PORT = 50007 # Arbitrary non-privileged port | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
s.bind((HOST, PORT)) | |
s.listen(0) | |
while 1: | |
conn, addr = s.accept() | |
print 'Connected by', addr | |
while 1: | |
data=conn.recv(1024) | |
if not data: break | |
conn.sendall(data) | |
print data | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment