how to reconnect with server after client terminates(reset)?

Discussion to talk about software related topics only.
Post Reply
savaliya_ambani
Posts: 19
Joined: Fri Dec 12, 2008 2:54 am

how to reconnect with server after client terminates(reset)?

Post by savaliya_ambani »

Dear SIR,

My NNDK MOD5282 is a client ,and sends the processed real time data we get after processing, to the Windows PC server ,where our server code is running.

Now,when i reset the NNDK board and try to reconnect to the server,than the connection is not accepted.i dont know what is happening and what to do?

The reverse is true,i.e. if server gets resetted,and comes into listen mode, than my client MOD5282 gets connected to it.

Thanks in Advance.
User avatar
yevgenit
Posts: 84
Joined: Fri Apr 25, 2008 12:47 am
Contact:

Re: how to reconnect with server after client terminates(reset)?

Post by yevgenit »

Regardless of the root reason, why the server doesn't accept the (TCP?) connection, try to reconnect with reasonable numbers of the attempts and with the reasonable interval. It will help, if the server is able to return to the listening after some timeout.
savaliya_ambani wrote:Now,when i reset the NNDK board and try to reconnect to the server,than the connection is not accepted.i dont know what is happening and what to do?
Yevgeni Tunik
Embedded/RealTime software engineer
https://www.linkedin.com/in/yevgenitunik/
________________________
User avatar
Forrest
Posts: 288
Joined: Wed Apr 23, 2008 10:05 am

Re: how to reconnect with server after client terminates(reset)?

Post by Forrest »

Sounds like the PC may not be closing the socket when the netburner loses connection. The netburner is probably trying to connect on the same open port number, the PC believes that this port is already in use (from the old netburner socket) and denies the connection. Just my guess.

I'd make the netburner connect with port 0, which would make it a random port number, instead of a hardcoded. The PC still needs a hard coded listen port.
Forrest Stanley
Project Engineer
NetBurner, Inc

NetBurner Learn Articles: http://www.netburner.com/learn
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: how to reconnect with server after client terminates(reset)?

Post by rnixon »

It sounds like you are describing a half open server socket connection, which means that the client reset, but the server does not know about it, so it still thinks its connected. This is usually overcome by the server checking the status of all open connections and closing ones that it thinks are no longer active.

If this is the case, then any client that tries to connect on the same source IP/Port number pair will not be able to. So you need to use a different source port number on your netburner, or use the 0 parameter for a random number. But in the end the server still needs to have some type of interaction to time out inactive connections, otherwise it will eventually run out of resources.
savaliya_ambani
Posts: 19
Joined: Fri Dec 12, 2008 2:54 am

Re: how to reconnect with server after client terminates(reset)?

Post by savaliya_ambani »

Thanks to all,

i have fixed the local port as well as destination port . Now,server also closes the fd by close(fd), and returns successfully . but still it is not getting connected immediately after that.It gets reconnected to the same port after very long time.

And it gets reconnected only when server restarts the tcp services,which we dont want to do.I suspect the resources are not getting released,because server just takes the decision of close(fd) instantly. And it may happen that some timers are also running. i Dont have any idea on that.

So,kindly let me know what exactly is happening and what can be the solution?

Thanking you all.
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: how to reconnect with server after client terminates(reset)?

Post by rnixon »

Hi,

If I understand your last post, you are saying the server (not the netburner) is not releasing the resource? I don't know if we can help with that, since the server is something else entirely. It does seem that if you need to reboot the server to make everything work properly it indicates the server is not actually releasing the resource, so there is something wrong in your server code.

One way to check this is to use the wireshark packet capture program. If you see the netburner send a syn to open a socket connection, and the server sends a rst, your problem is definitely that the server needs to be modified to close half open sockets. Maybe it already is, but the timeout is long and that is what you are seeing now.
thomastaranowski
Posts: 82
Joined: Sun May 11, 2008 2:17 pm
Location: Los Angeles, CA
Contact:

Re: how to reconnect with server after client terminates(reset)?

Post by thomastaranowski »

If you're server is listening on a specified port number, and the client drops out, and you want them to be able to reconnect in some reasonable time, you can specify the SO_REUSEADDR option on the server socket to allow the server to reuse the local port before the prior connection has timed out.
Post Reply