I have developed a small server-client (server: python client: c#) application running on localhost and port 6000. When I start my computer, the client fails to connect to the server on the first attempt. However, if I close and reopen the application, the connection is successful/
def start_server():
host, port = "localhost", 6000
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))
server_socket.listen(1)
print("nServer is waiting...")
connection, address = server_socket.accept()
return connection
private void ConnectToServer()
{
client = new TcpClient();
try
{
client.Connect("127.0.0.1", 6000);
}
catch (Exception ex)
{
MessageBox.Show("Connection Error: " + ex.Message);
}
}
New contributor
Fatih Haslak is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.