I've wrote a simple socket server in python (OS X). I want the server to restart when a client terminate the communication, so that the client can do a reconnect to the server. Look at the code below, what do i have to do at the "lost contact" IF? I'm completely new to Python.
Here is the code:
import socket
import os
s = socket.socket()
host = socket.gethostname()
port = 5555
os.system('clear')
print 'Server started'
print 'Waiting'
s.bind((host, port))
s.listen(5)
c, addr = s.accept()
print 'Contact', addr
while True:
msg = c.recv(1024)
if not msg:
s.close
print "Lost contact"
exit ()
else:
print msg
s = socket.socket()bes = socket.socket(socket.AF_INET, socket.SOCK_STREAM)? Also, why do you need to restart the server? The client should be able to reconnect. Also, can you add the client software - perhaps that is the issue. Lastly, I believe that theosmodule is outdated - I may be wrong though (It does have its uses... I think )socket.socket()aresocket.AF_INETandsocket.SOCK_STREAMso they can be left out.