Jump to content

Recommended Posts

Hi,

I have a situation where the TWSocketServer send data two time at second in a TCP packet.

If the client for some reason is working and is busy (sending data on internet) after some time seems that the server hangs.

There is a metod to avoid this (eg. reading the size of send buffer or similar)?

In this case is not important if the data is read from client but is important that the server still running also if client is blocked or in error.

Thanks for your help!

 

Share this post


Link to post
6 minutes ago, mirco. said:

I have a situation where the TWSocketServer send data two time at second in a TCP packet.

If the client for some reason is working and is busy (sending data on internet) after some time seems that the server hangs.

 

If the server is written correctly, it will run for weeks without hanging, despite unfriendly clients and internet issues, and my servers do exactly that. 

 

The most likely explanation for hanging is you are ignoring all client socket errors, and writing so much data that the local buffers overflow. 

 

Generally, ICS applications are written to send data within the OnDataSent event which is fired when the buffers have space for more data to send, look at the HTTP and FTP client components.

 

There is a property BufferedByteCount that shows unsent data, but you generally don't need to use this when using OnDataSent to send the next block from your stream.

 

Angus

 

Share this post


Link to post

Yes, I don't use OnDataSent but until now I have never had any problems.

The problems started with a client that repeats sending data over the internet and is very unstable. Changing the code now to use the event is quite complicated.
For now can I use a semaphore to make sure not to send more data until the OnDataSent event is called?
Can I find myself in a situation where OnDataSent is not called (if the client is blocked for example)?
If I have no data to send when OnDataSent is activated, how can I know when to recall the Send?
I looked at the examples several times but I don't remember anything about this way of working.
Thanks anyway

Share this post


Link to post

You can put data into the sendbuffer (That is call one of the send method). In OnDataSend event Handler, you set a flag to true and you reset it when you call send. Initialize the flag to true when the connection is established. Before calling one of the send methods, check the flag.

 

The question is what will you do when the client doesn't receive fast enough ? Just throw away the data ? If you buffer it, then you'll have again a problem of too much data eating all available memory.

 

Share this post


Link to post

Yes this is clear. If the client is not fast enough, sooner or later some data is lost. The problem is that from the server side I have to be sure that no client can undermine the stability of the server, so I imagined a flag solution in the OnDataSend event if this can be enough. So far I have never had problems with ICS (I like them very much) while also sending MB of data but with the unstable client I need to find a solution.
Thanks

Share this post


Link to post

You should also monitor the session closed event.

If your client stop reading data without disconnecting, the timeout can be very long. I suggest you simply abort (Not close) the connection for that client.

 

Share this post


Link to post

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
×