Skip to content

Instantly share code, notes, and snippets.

@monsterxx03
Created June 18, 2013 15:46
Show Gist options
  • Save monsterxx03/5806496 to your computer and use it in GitHub Desktop.
Save monsterxx03/5806496 to your computer and use it in GitHub Desktop.
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('127.0.0.1', 8001))
s.listen(2)
while 1:
conn, addr = s.accept()
print 'connected by', addr
conn.sendall('response\n')
while 1:
data = conn.recv(1024)
if not data: # client stop connection
break
print 'receive %s' % data
conn.sendall('resping')
print 'conn close'
conn.close()
s.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment