I'm trying to set up a socket for p2p communication. A I found this code, but I'm having a hard time understanding the code. What does SOL_SOCKET, as well as SOL_REUSE?
Could someone help me go through this code?
#!/usr/bin/env python
import socket, sys
self_broken = False
def wait(c):
print('waiting...')
c.send('waiting')
broken = True
while broken:
status = c.recv(1024)
if status == 'working':
print(status)
if self_broken:
c.send('broken')
else:
c.send('starting')
broken = False
c.close()
def main():
s = socket.socket()
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
host, port = socket.gethostname(), 10001
s.bind((host, port))
s.listen(1)
while True:
c, addr = s.accept()
status = c.recv(1024)
print(addr[0] + ':' + str(addr[1]) + ' > ' + status)
if status == 'broken':
wait(c)
else:
print(status)
c.close()
s.close()
main()
I found this explanation, but it is for C, does it apply for Python as well? This is for C, is it the same for Python?
EDIT: Can anyone tell med what the 'c' does? it's in wait(c), c.send and c.close.