Jump to content
Sign in to follow this  
oshaker

What is the safe way for TCP reconnect

Recommended Posts

oshaker

I have modified the example provided by kip for TCP client-server example. I added a mechanism to enable client to connect (wait for the server) if the server was not up when the client runs and finds no server, or if the server dies while client was connected and enable it to reconnect if the server is up again. Please look at the attached codes and tell me if this is the correct way to do it, advise if there are better ways.

Another thing, server and client processes are eating the CPU, is there a solution for this?

TCP_Client_Server_Kip.rar

Edited by oshaker

Share this post


Link to post
Share on other sites
oshaker

Okay, I can answer my self now.

While 1
WEnd
is incorrect way to loop for ever because it eats CPU. I should have used:

While 1
Sleep(100)
WEnd

A simpler way, yet effective to reconnect to the server. Modified code is attached. Thanks to the original creator of the TCP UDF. Now is there a way to stop $hsocket increment while the server is down? If $hsocket keeps incrementing what will happen? Is the client going to die at some time?

TCP_Client_Server.rar

Edited by oshaker

Share this post


Link to post
Share on other sites
oshaker

Guys where are you?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×