I have a Python Socket server
program, and for whatever reason the program can't bind the host and port together.
Here's my code:
import socket
import sys
host = ""
port = 9999
s = socket.socket()
try:
("Binding socket to port: " + str(port))
s.bind((host, 9999))
s.listen(5)
except socket.error as msg:
print("Socket binding error: " + str(msg) + "\n" + "Retrying...")
conn, address = s.accept()
print("Connection has been established: " + "IP " + address[0] + " Port " + str(address[1]))
while True:
cmd = input()
if cmd == "quit":
conn.close()
s.close()
sys.exit()
if len(str.encode(cmd)) > 0:
conn.send(str.encode(cmd))
client_response = str(conn.recv(1024), "utf-8")
print(client_response, end=="")
conn.close()
I've had it print the error, and it says: Socket binding error: [Errno 10048]
Only one usage of each socket address (protocol/network address/port)
is normally permitted.
Does anyone know what this means and what I should do?