I'm playing with sockets in python, and I can't find a way to close my "server" connection in the command line. ctrl+c, ctrl+z do not work.
my server.py file:
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((socket.gethostname(), 1235))
s.listen(5)
while True:
clientsocket, address = s.accept()
print(f"connection from {address} has been established!")
clientsocket.send(bytes("Welcome to the server!", "utf-8"))
clientsocket.close()
if I make updates to this file I have to close the terminal and rerun the script. I have to change the port number because the original port stays occupied. The guy in the tutorial has to do the same thing, but I can't imagine that this is the best way to do things. Is there a command that will close the connection, clear the ports, etc., allowing me to restart the script?
- I'm on Windows 10
- SO_REUSEADDR does allow me to restart the script on the same port, however I am still not able to stop the script. I still have to close the terminal to stop the script.