I'm writing TCP client server software using C#. I want client be connected with server automatically as soon as server started. To do this task, client may need to know whether the server is started or not. But how, is it possible?
My situation: There is one client and one server on the same LAN network. Each one knows IP address of other one. Here is code section to make connection between them:
Server side:
// Starting the Server ...
TcpListener serverSocket = new TcpListener(8888);
TcpClient clientSocket = default(TcpClient);
serverSocket.Start();
...
// Listening for client's connection in a thread ...
while (true)
{
clientSocket = serverSocket.AcceptTcpClient();
msg(" The client connected");
}
...
Client side:
// Here, client makes connection to the server when user clicks a button
clientSocket.Connect("192.168.1.1", "8888");
...