Thread View: borland.public.cppbuilder.internet.socket
3 messages
3 total messages
Started by Ofer Gaatone
Sun, 17 Sep 2006 13:00
Restart connection
Author: Ofer Gaatone
Date: Sun, 17 Sep 2006 13:00
Date: Sun, 17 Sep 2006 13:00
17 lines
1734 bytes
1734 bytes
Hi, i write a client TCP application using Bcb6 under Win-2000. The application uses the connect, send, recv, etc API and NOT components. Once the server is up and opens a socket the client create the connection once and send & recv message. It closes the connection just when the client terminate it's work. If for any reason the server crushes and start immediately again, the connection is lost, and since i don't get any error (how come ?) the connection between the client and the server is broken and i have to restart the client to fix it. How can the client identify that the server crushed ? How come there is no error when sending a message on a socket when there is no server to answer ? Thanks Ofer
Re: Restart connection
Author: Michel Leunen
Date: Sun, 17 Sep 2006 13:37
Date: Sun, 17 Sep 2006 13:37
17 lines
1455 bytes
1455 bytes
Ofer Gaatone wrote: > How come there is no error when sending a message on a socket when there > is no server to answer ? The send() and recv() functions return an error (SOCKET_ERROR) if the connection has been broken by the remote host. In this case, WSAGetLastError() yields WSAENETRESET. Michel -- ---------------------------------------- Michel Leunen mailto: see my homepage. C++Builder, BCC5.5.1 Web site: http://www.leunen.com/ ----------------------------------------
Re: Restart connection
Author: Remy Lebeau (TeamB)
Date: Mon, 18 Sep 2006 06:31
Date: Mon, 18 Sep 2006 06:31
26 lines
2108 bytes
2108 bytes
"Ofer Gaatone" <ofer@roseman.co.il> wrote in message news:450d3815$1@newsgroups.borland.com... > How can the client identify that the server crushed ? The socket will report an error whenever you tr to read/write on the invalid connection. > How come there is no error when sending a message on a socket > when there is no server to answer ? There is. However, abnormal disconnects are very difficult to detect in a timely manner. It may take several hours for the OS to detect that a socket connection has been lost. In the meantime, the socket happily continues accepting read/write requests. The reads will return no data, and the writes will be buffered and never sent. As such, you should be implementing your own timeouts in your code, and also implemennting keepalives into your data protocol if possible. Have the client send a keepalive packet periodically, and have the server reply to it. If the client does not receive a reply, then close the connection and reconnect. If the server does not receive any data from a client for a period of time, then close the connection and wait for a new connection. Gambit
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads