def hello(ip, port, sockobj):
# Receive the browser's HTTP request header, but we'll ignore it
httpheader = sockobj.recv(512)
response_body = "
Hello World\
Hello World!
"
# Send a simple HTTP header before the actual HTML
sockobj.send("HTTP/1.1 200 OK\r\nContent-Length: " +
str(len(response_body)) + "\r\n\r\n" + response_body)
# close my connection with this user
sockobj.close()
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)