Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reconnect the clients to server?

My server program (socket stream) is running and it accepts the clients. Due to some abnormal condition, server is getting terminated. The other side clients are waiting for server reply. How to I reconnect the running clients to new server? any functions in sockets?

like image 694
loganaayahee Avatar asked Apr 25 '13 09:04

loganaayahee


People also ask

How do you reconnect to the server?

Automatically Reconnect to a Server on a PCOpen File Explorer and select This PC. Select the Computer tab, then select Map Network Drive. Enter the IP address of the server or share name to give the path of the shared drive, then check the box next to Reconnect at sign-in. Wait for the drive to be mapped.

Why is client not connecting to server?

The network configuration has changed (ie. The internal server IP has changed, the dynamic internet IP has changed, port 8082 is blocked, etc.). There is a firewall blocking the connection (ie. Windows Firewall on either the server or the client, 3rd party firewall software, the firewall on the router).


1 Answers

A socket that had been connect()ed once cannot be reused with another call to connect().

The steps to connect to a TCP server and read/write some data are as follows (pseudo code):

sd = socket(...) // create socket descriptor (allocate socket resource)
connect(sd, server-address, ...) // connect to server
read/write(sd, data)  // read from server 
close(sd) // close /socket descriptor (free socket resource)

In case the server goes down after connect all the client could and shall do is

close(sd) // close socket descriptor (free socket resource)

and then start over beginning with:

sd = socket(...) // create socket descriptor (allocate socket resource)
...

Starting over beginning with:

connect(sd, server-address, ...) // connect to server
...

would probably lead to undefined behaviour, but at least to an error.

like image 50
alk Avatar answered Sep 29 '22 08:09

alk