I am working on a TCP socket server for a client and i am having a problem. Everything works except for one thing: i can't figure out how to have the server tell the client that the server is going down.

I have the SocketServer running as a windows service. It starts and stop just fine. I also wrote a test program that connects to the Server and fetchs data from a MySQL db. Now, The SocketServer itself will be restarting once each week. However, the program that will be connecting to it is provided by a 3rd party vendor. So I can't really control how the connections happen. The program they are running is designed to always be running. What i need is a way to send their program a signal that says " the server is restarting". they are willing to modify their program to create connections after they are lost.

The problem is getting the server to send any kind of signal like that. I can't send some text that says the server is going down. I have to find a way to tell their socket to close itself ( or something similar )

any ideas?

(and im new, hello )

(1) Welcome!

(2) Why can't you send a text control packet?

(3) Wouldn't it make more sense to have the client timeout and restart? That way, if the client times out (no matter the cause -- server goes down, 5-year-old with scissors cuts the cat5e cable, etc.), then it will know to restart itself.

Just thoughts.

Jeff

(1) Welcome!

(2) Why can't you send a text control packet?

(3) Wouldn't it make more sense to have the client timeout and restart? That way, if the client times out (no matter the cause -- server goes down, 5-year-old with scissors cuts the cat5e cable, etc.), then it will know to restart itself.

Just thoughts.

Jeff

We ended up going with option 2 from your list. They weren't happy about it but I'm not really concerned since they aren't my client. After talking to someone with tons of python experience, what they wanted really wasn't possible given the way I built the server. I used the TCPSocketServer built in to python as the base for what i wrote. What the vendor wanted was something that would require access to the underlying TCP/IP stack.

Also, they said they can't do timeouts. I'm not sure what language they are using but I'm sure thats just a load of BS.

Anyway, we have reached an agreement and all is well.

So, there is more to the story. One minor concern we both had is that if the TCP server were to shutdown hard or unexpectedly, his (the vendor's) program wouldn't get the "exit" signal. Without that, his program still thinks the TCP server is there, and ho-hums along under the delusion that its not getting any data because there is nothing to send.

However, he is going to put in some hooks for me to send messages externally, as a fail safe.

what prompted this issue being reopened is that the 7 locations that have my TCP server lost power. the vendors program connects to my server remotely through a VPN so they were unaffected. So, for 3 days the vendor wasn't getting data and management wasn't happy.

also, they don't use time outs on their sockets. His program is in C#, if that matters. but how it determines if a service is there is with a machine ping. if the machine responds, he then tries to connect on the specified port ( unless connected ).

a long, and probly confusing post, but basically i need help. is there anyway i can get access to the TCP layer to send the disconnect?

See, the thing about a hard shutdown or unexpected crash is that there's not time to send packets or anything before the server's off-line. The only way I can see to do this is if there's some sort of stay alive exchange and your clients time out if they don't receive a hit back for a while.

If their box pings your server and it doesn't ping back what happens?

Do you mean you're trying to save the state of the connection before the failure and restart it at that state or re-establish a new connection?

I'm a n00b, so please don't take anything I've said as the truth :-D.

See, the thing about a hard shutdown or unexpected crash is that there's not time to send packets or anything before the server's off-line. The only way I can see to do this is if there's some sort of stay alive exchange and your clients time out if they don't receive a hit back for a while.

Thats a good idea. I will see if we can arrange something like that.

If their box pings your server and it doesn't ping back what happens?

Then the socket would close. but, it wont ping it after the socket is created. so if the server dies, the client doesn't get the socket being closed. since the client didn't get the signal that the socket is done, it wont do anything. it just assumes no news is good news, so to speak

Do you mean you're trying to save the state of the connection before the failure and restart it at that state or re-establish a new connection?

I just need to get the socket to close on the client end. if they actually get the socket close signal, then their stuff starts trying to connect again.

This article has been dead for over six months. Start a new discussion instead.