c - How to reconnect the clients to server? -
my server program (socket stream) running , accepts clients. due abnormal condition, server getting terminated. other side clients waiting server reply. how reconnect running clients new server? functions in sockets?
a socket had been connect()
ed once can not reused call connect()
.
the steps connect tcp server , read/write data follows (pseudo code):
fd = socket(...) // create socket describtor (allocate socket resource) connect(fd, server-address, ...) // connect server read/write(fd, data) // read server close(fd) // close /socket descriptor (free socket resource)
in case server goes down after connect
client , shall is
close(fd) // close /socket descriptor (free socket resource)
and start on beginning with:
fd = socket(...) // create socket describtor (allocate socket resource) ...
starting on , beginning with:
connect(fd, server-address, ...) // connect server ...
would propably lead undefined behaviour, @ least error.