[CentralOH] Network file

Eric Floehr eric at intellovations.com
Tue May 25 01:38:43 CEST 2010


Here it is:

import os
import sys
import socket

CR = chr(13)
LF = chr(10)

listen_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
listen_sock.bind(('127.0.0.1',0))
listen_sock.listen(5)
print 'Listening:', listen_sock.getsockname()

while True:
	sock, peername = listen_sock.accept()
	print 'Connection from:', peername, sock.getpeername()

	while True:
		msg = sock.recv(200)
		if not msg:
			break
		print 'Question:', msg
		msg = eval(msg)
		sock.send(('Answer: %s\n' %msg).replace('\n', CR+LF))
	sock.close()

listen_sock.close()
sys.exit(0)


More information about the CentralOH mailing list