I'm using DreamHost as a hosting-provider for my server.py .If I run my code locally, the setsockopt function succesfully sets the parameter SOCKET_REUSEADDR to True and I can effectively reuse the port. But when I run server.py on the hosting, I get the error '[Errno 98] Address in use'
Running `ps aux | grep python' and manually closing processes using kill -9 PID gives me the possibility to reuse the port in the beginning. But doesen't that mean that 'socket.setsockopt' doesen't work ?
server.py
host = 'Dreamhost_IP'
port = 33000
server_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
server_socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
server_socket.bind((host,port))
.
.
.
.
.
if __name__=="__main__":
server_socket.listen(5)
print('waitin for connections')
accept_thread = threading.Thread(target = accept_connections)
accept_thread.start()
accept_thread.join()
server_socket.close()
I'm expecting to be able to reuse the desired port by overriding the wait time with SO_REUSEADDR. If I use '127.0.0.1' as 'host' and 33000 as 'port', I can successfully rerun the server on that port.