Created
July 20, 2010 19:29
-
-
Save jbalogh/483424 to your computer and use it in GitHub Desktop.
An echo server so I remember how to use sockets.
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 | |
def main(): | |
server = socket.socket() | |
server.bind(('localhost', 9999)) | |
server.listen(1) | |
print 'listening on :9999' | |
client = server.accept()[0] | |
while 1: | |
msg = client.recv(1024).strip() | |
print msg | |
if msg == 'die': | |
client.close() | |
server.close() | |
break | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment