WSocket sometimes stops to receive data
9 answers - 1865 bytes -

Hi guys,
I'm writing with D7 Pro an application composed by three different layers,
which communicate by ICS WSocket with a simple TCP/IP based protocol.
The architecture is the following:
The first layer, call it Data Collector, connects his WSockets to the
WSocketSerevr of the second layer, call it Server, and push some records to it.
The Server has another WSocketServer that listens for clients (third layer)
and as soon as a client connects, the Server push the records received by
Data Collector to all connected clients.
I have some problem I cannot resolve.
1)Sometimes all the chain seems to stop communicating.
I noticed that if I move/resize/minimize the windows of the applications,
often the communications stops immediately.
If I don't interact with the executables GUI, the transmissions goes for a
longer time, but after some minutes it stops anyway: sometimes few dozens
of seconds sometimes 9 or 10 minutes.
The records are quite small, from 60 to 200 bytes.
The average rate is 50/60 records every second, with peaks of 150/160: the
CPU usage is very low, I don't think is a performance problem.
I have Exception trappers in every method involved in communication
(ClientDataAvailable, ChangeState, ClientConnect, etc.) but non error is
raised.
2)I'm not able to establish connections on a LAN: if all the executable are
on the same machines I connect without any problem, but if they run on
different machines.
I'm pretty sure I'm doing something wrong with WSocket properties.
I set Addr on the client and Address on the server with the IP address of
server machine, the Port on same value on both sides: is this enough to
make a connection on a LAN?
Thank you in advance for you replies.
Ciao.
No.1 | | 1186 bytes |
| 
1)Sometimes all the chain seems to stop communicating.
Some GUI operation, or some interface component lock up the whole thing. If
that happend in your environment, you can solve the problem by making all
communication occur within a worker thread having his owen message pump.
When you use multithreading with ICS, be sure to either create the ICS
component within the context of the thread, typically at the beginning of
thread's execute method. Alternatively, you can call threadetach et
threadattach to "move" a component from a thread context to another thread
context.
I set Addr on the client and Address on the server with the IP address of
server machine, the Port on same value on both sides: is this enough to
make a connection on a LAN?
For the server (listening) part, you usually set the address to 0.0.0.0
which is the default. This makes the component listening on all the
interfaces. If you setup an IP address, the component listen only from that
interface. When you use loopback address (127.0.0.1) to listen "locally", it
wont' work with any of the physical interfaces ! That may be your problem.
No.2 | | 2870 bytes |
| 
Hello Geppy,
1. 32 KB peak is still low traffic, so (as you also say) it cannot be a
performance problem. Could be that the stop communictaion when resizing
a form is a coincidence since you say it stops anyway after a while. I
never had that problem so difficult to advice.
I assume that if one application in the chain is stopping that the chain
is broken and no application will send anymore ? So maybe the problem is
in only 1 application. Can you try to make just client + server to see
if same problem arrise ?
If you can make a simple project to demonstrate the behaviour I and
other can do a test run for debug.
2. Should work on network also. Try to listen on address 0.0.0.0 and
dont touch LocalAddress and LocalPort properties ! The IP of machine
should also work, but try first to listen on all interfaces.
Rgds, Wilfried [TeamICS]
http://www.mestdagh.biz
Friday, November 11, 2005, 15:52, Geppy Piloni wrote:
Hi guys,
I'm writing with D7 Pro an application composed by three different layers,
which communicate by ICS WSocket with a simple TCP/IP based protocol.
The architecture is the following:
The first layer, call it Data Collector, connects his WSockets to the
WSocketSerevr of the second layer, call it Server, and push some records to it.
The Server has another WSocketServer that listens for clients (third layer)
and as soon as a client connects, the Server push the records received by
Data Collector to all connected clients.
I have some problem I cannot resolve.
1)Sometimes all the chain seems to stop communicating.
I noticed that if I move/resize/minimize the windows of the applications,
often the communications stops immediately.
If I don't interact with the executables GUI, the transmissions goes for a
longer time, but after some minutes it stops anyway: sometimes few dozens
of seconds sometimes 9 or 10 minutes.
The records are quite small, from 60 to 200 bytes.
The average rate is 50/60 records every second, with peaks of 150/160: the
CPU usage is very low, I don't think is a performance problem.
I have Exception trappers in every method involved in communication
(ClientDataAvailable, ChangeState, ClientConnect, etc.) but non error is
raised.
2)I'm not able to establish connections on a LAN: if all the executable are
on the same machines I connect without any problem, but if they run on
different machines.
I'm pretty sure I'm doing something wrong with WSocket properties.
I set Addr on the client and Address on the server with the IP address of
server machine, the Port on same value on both sides: is this enough to
make a connection on a LAN?
Thank you in advance for you replies.
Ciao.
No.3 | | 1586 bytes |
| 
At 16.45 11/11/2005 +0100, you wrote:
Hi Francois,
1)Sometimes all the chain seems to stop communicating.
>
>Some GUI operation, or some interface component lock up the whole thing. If
>that happend in your environment, you can solve the problem by making all
>communication occur within a worker thread having his owen message pump.
>When you use multithreading with ICS, be sure to either create the ICS
>component within the context of the thread, typically at the beginning of
>thread's execute method. Alternatively, you can call threadetach et
>threadattach to "move" a component from a thread context to another thread
>context.
!
I dropped Indy to avoid the threads nightmare and now you tell me I need
threads in ICS too?
<vbg>
, let's go with thread :)
I set Addr on the client and Address on the server with the IP address of
server machine, the Port on same value on both sides: is this enough to
make a connection on a LAN?
>
>For the server (listening) part, you usually set the address to 0.0.0.0
>which is the default. This makes the component listening on all the
>interfaces. If you setup an IP address, the component listen only from that
>interface. When you use loopback address (127.0.0.1) to listen "locally", it
>wont' work with any of the physical interfaces ! That may be your problem.
I'll try in this way.
Thank you very much.
No.4 | | 393 bytes |
| 
Hello Geppy,
I dropped Indy to avoid the threads nightmare and now you tell me I need
threads in ICS too?
<vbg>
I read context more like: "if you have a component or interface that
locks up, then you can solve it by threading".
So I should first try to find out what / wy before go to threading
Rgds, Wilfried [TeamICS]
http://www.mestdagh.biz
No.5 | | 2097 bytes |
| 
At 17.17 11/11/2005 +0100, you wrote:
>Hello Geppy,
Hello Wilfried,
>1. 32 KB peak is still low traffic, so (as you also say) it cannot be a
>performance problem. Could be that the stop communictaion when resizing
>a form is a coincidence since you say it stops anyway after a while. I
>never had that problem so difficult to advice.
It could be, but half the times I resize/move/minimize/maximize the windows
the communication stops immediately.
>I assume that if one application in the chain is stopping that the chain
>is broken and no application will send anymore ? So maybe the problem is
>in only 1 application. Can you try to make just client + server to see
>if same problem arrise ?
Yes, I already tried a simple client/server socket connection cutting
almost all code not involved in communication, but the problem is the same.
All the Socket communication code is taken directly from your samples
(Server1.zip, http://tinyurl.com/cqkmh ) as we discussed some days ago in
this mailing list (thread 'Sending a mix of text and records through
TWSocket').
The only difference is in some new methods added to manage the records
manipulation and a loop for all connected clients to transmit the data
through the second WSocketServer to third layer's clients.
The hard thing it that no exceptions at all are raised, I don't understand
which is the broken ring.
The sockets maintain their connections but no data is transmitted/received.
>If you can make a simple project to demonstrate the behaviour I and
>other can do a test run for debug.
Since they are three different projects and a lot of code, I don't want to
abuse of your patience.
I'll try first with threads as suggested by Francois and if I'll have no
luck, I'll post the code here.
Thank you very much Wilfred.
Ciao.
No.6 | | 2739 bytes |
| 
Hello Geppy,
Yes, I already tried a simple client/server socket connection cutting
almost all code not involved in communication, but the problem is the same.
Can you mail me this one. Probably (as always) nothing on television, so
I might as well look into it :)
ps.: unless there is per coincidence something interesting on TV :)
Rgds, Wilfried [TeamICS]
http://www.mestdagh.biz
Friday, November 11, 2005, 18:19, Geppy Piloni wrote:
At 17.17 11/11/2005 +0100, you wrote:
>>Hello Geppy,
Hello Wilfried,
>>1. 32 KB peak is still low traffic, so (as you also say) it cannot be a
>>performance problem. Could be that the stop communictaion when resizing
>>a form is a coincidence since you say it stops anyway after a while. I
>>never had that problem so difficult to advice.
It could be, but half the times I resize/move/minimize/maximize the windows
the communication stops immediately.
>>I assume that if one application in the chain is stopping that the chain
>>is broken and no application will send anymore ? So maybe the problem is
>>in only 1 application. Can you try to make just client + server to see
>>if same problem arrise ?
Yes, I already tried a simple client/server socket connection cutting
almost all code not involved in communication, but the problem is the same.
All the Socket communication code is taken directly from your samples
(Server1.zip, http://tinyurl.com/cqkmh ) as we discussed some days ago in
this mailing list (thread 'Sending a mix of text and records through
TWSocket').
The only difference is in some new methods added to manage the records
manipulation and a loop for all connected clients to transmit the data
through the second WSocketServer to third layer's clients.
The hard thing it that no exceptions at all are raised, I don't understand
which is the broken ring.
The sockets maintain their connections but no data is transmitted/received.
>>If you can make a simple project to demonstrate the behaviour I and
>>other can do a test run for debug.
Since they are three different projects and a lot of code, I don't want to
abuse of your patience.
I'll try first with threads as suggested by Francois and if I'll have no
luck, I'll post the code here.
Thank you very much Wilfred.
Ciao.
No.7 | | 724 bytes |
| 
At 18.34 11/11/2005 +0100, you wrote:
>Hello Geppy,
Hello Wilfried,
Yes, I already tried a simple client/server socket connection cutting
almost all code not involved in communication, but the problem is the same.
>
>Can you mail me this one. Probably (as always) nothing on television, so
>I might as well look into it :)
>
>ps.: unless there is per coincidence something interesting on TV :)
I need to translate a bit the GUI, some methods and variable names since it
is written in italian.
I cannot do it this evening, maybe tomorrow.
Wilfried, thank you very much for your effort :)
Ciao.
No.8 | | 1371 bytes |
| 
Hello Geppy,
I answer in more detail private to you and here only with the things
that are interesting and/or can benefit other users.
TWSocket did not stop receiving, it only looked that way. Reason is
following: At some point you receive data like this:
Count := Receive(Ricevuti + WritePtr, RcvdSize - WritePtr);
This is perfecly K, because you receive maximum the size of the buffer
and some lines further if not enough buffer space then you reallocate
memory.
But when you are receiving the binary data of a given length you check
of course if you have the complete packet as this:
if WritePtr = RcvdCount then
While this is also K there is the problem. You receive at high speed
and you go move/resize a form. At that moment you send thousands of
messages (mouse_move etc) to the message pump. This is no problem but
you slow it down for a fraction of time. After the move there is a
little more bytes in winsock buffer and the Receive will receive too
many, and WritePtr is then larger than RcvdCount.
Solution is when you receive binary data of given length to receive max
just the amount you need. If there is more in winsock buffer then
DataAvailable will immediatly fire again with the rest of the data.
Rgds, Wilfried [TeamICS]
http://www.mestdagh.biz
No.9 | | 575 bytes |
| 
At 18.52 12/11/2005 +0100, you wrote:
>Hello Geppy,
>
>I answer in more detail private to you and here only with the things
>that are interesting and/or can benefit other users.
[SNIP]
>Solution is when you receive binary data of given length to receive max
>just the amount you need. If there is more in winsock buffer then
>DataAvailable will immediatly fire again with the rest of the data.
Hi Wilfried,
thank you very much, it works :)
Ciao.