def hello(ip, port, sockobj): httpheader = sockobj.recv(512) # Receive HTTP header, but we'll ignore it mycontext['pagecount'] = mycontext['pagecount'] + 1 response = ("Hello World" "

Hello World!

" "

You are visitor "+str(mycontext['pagecount'])+"") response = ('HTTP/1.1 200 OK\nContent-Type: text/html\nContent-Length: '+ str(len(response))+'\nServer: Seattle Testbed\n\n'+response) sockobj.send(response) # close my connection with this user sockobj.close() mycontext['pagecount'] = 0 if len(callargs) > 1: raise Exception("Too many call arguments") # Running remotely: whenever this vessel gets a connection # on its IPaddress:Clearinghouseport it'll call hello elif len(callargs) == 1: port = int(callargs[0]) ip = getmyip() # Running locally: whenever we get a connection # on 127.0.0.1:12345 we'll call hello else: port = 12345 ip = '127.0.0.1' server_socket = listenforconnection(ip, port) while True: try: ret_ip, ret_port, ret_socket = server_socket.getconnection() hello(ret_ip, ret_port, ret_socket) except SocketWouldBlockError: sleep(0.1)