Python to write a simple server, execution failed

Server side code.: server.py
import socket
sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
host=socket.gethostname()
sock.bind((host,8001))
sock.listen(5)
while True:
connection=sock.accept()
try:
connection.settimeout(5)
buf=connection.recv(1024)
if bug == '1':
connection.send('Welcome to server!')
else:
connection.send('please go out!')
except socket.timeout:
print 'time out'
connection.close()

The client code.: client.py
import socket
import time
sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
host=socket.gethostname()
sock.connect((host,8001))
time.sleep(2)
sock.send('1')
receive=sock.recv(1024)
print receive
sock.close()


The first implementation of server.py, in the implementation of client.py
The shell implementation of the results is as follows, in accordance with the normal words should print'Welcome to server! '.
>>> ================================ RESTART ================================
>>>

>>> ================================ RESTART ================================
>>>

Started by Zebulon at February 08, 2016 - 11:47 PM

I say the system in Python 2.7.5 debugging: No, connection setTimeout method.

Posted by Clifford at January 01, 2017 - 11:20 PM