Re: [twsocket] multithread server

2011-08-18 Thread Lukáš Skála

hi,
I always call Receive (even if RcvdCount returns zero). When RcvdCount 
returns zero then Receive returns -1 value. Is it normal?
What is property Multithreaded in TWServerSocket? Should it be set to 
TRUE? In demo application property is set to FALSE and only client 
sockets are set to TRUE.


Now I have no idea where is problem with service hanging. Any idea where 
to look is welcome.

Thanks
Lukas Skala


Dne 17.8.2011 18:18, Wilfried Mestdagh napsal(a):

Hi,

If OnDataAvailable triggers then you have to try to receive data, even if 
RcvdCount (wich is unreliable) returns 0. If you don't receive then 
OnDataAvailable will be called again in a closed loop en that is probably what 
happens.




--
lukas skala
envinet a.s.
divize projektu a inzenyringu (project and engineering division)
modrinova 1094
674 01 trebic

tel: +420 568 409 862 (811)
fax: +420 568 409 875
gsm: +420 724 461 062
icq: 66842878
eml: lukas.sk...@envinet.cz, luky.sk...@gmail.com
www: http://envinet.cz




--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] multithread server

2011-08-18 Thread Lukáš Skála

hi,
thank for reply.

there are about 150 clients (in average) connected at the same time. 
sometimes program hang after 15 minutes of running, sometimes after 
several hours.


I think there is no memory problem because server has a lot of memory 
and when I check it using taskmanager there is a lot of free memory 
(service itself is consuming about 58 mb of RAM), procesor time of the 
process is below 1%. There are about 10 connection in TIME_WAIT state. 
Values are taken when service is running without problem, I will check 
it again when it will hang.


I am not sure what does TIME_WAIT means - by googling I have found that 
it is closing socket waiting for final messages handshaking - is it 
true? I hope it is not my problem because if client is not active (1 
minute) it is disconnected by the server. Is it possible that sockets 
which were not correctly disconnected (e.g. clients was disconnected 
from network) will stay in TIME_WAIT state? Even when server close them 
explicitly after communication timeout?


Service is running on more servers and it seems to work fine with less 
clients. I have problem only on one server - unfortunatelly there is no 
chance to debug service (only write to log is possible).


I will try to test in GUI application.

I did some test and now I have 2 version:

version 1: incoming data are received in main thread and are written to 
buffer of client, client has own thread to process data in buffer
version 2: data are received in client thread (in same way as in demo 
thread application)


It seems version 1 is more stable but it will hang too. Processing of 
data is done by the same procedures so I hope there is no difference.



Lukas


Dne 18.8.2011 11:26, Wilfried Mestdagh napsal(a):

Hi,

When receive returns -1 then it indicate an error, but you don't have to
worry about it. If MultiThread is True then TWSocket uses his own message
pump. You can use it yourself also or override it.

If OnDataAvailable is called in a closed loop then there is something wrong
with winsock.

You tell that it happens after a while when many clients connecting (and
disconnecting ???). Is this predictable?

Is it possible you have many sockets in TIME_WAIT state or that you have run
out of non-pagable memory? You can check the former with 'netstat -a'. The
latter with task manager. Note that a socket uses 10kb (or more depeniding
on traffic), that non-pagable memory is maximum 1/8 of total real memory
(not virtual).

Have you the same problem if you run the same application in a GUI or
console application?

You can set wsoNoReceivedLoop for each client then OnDataAvailable is not
called in closed loop but with a message handler. Eventually more easy to
debug?




--
lukas skala
envinet a.s.
divize projektu a inzenyringu (project and engineering division)
modrinova 1094
674 01 trebic

tel: +420 568 409 862 (811)
fax: +420 568 409 875
gsm: +420 724 461 062
icq: 66842878
eml: lukas.sk...@envinet.cz, luky.sk...@gmail.com
www: http://envinet.cz




--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] Triggering DataAvailable

2011-07-27 Thread Lukáš Skála
I have very simillar situation, my clients (embedded units connected 
through GPRS) expect some sequence of bytes from server after 
connecting. Clients are able to send their data after they receive this 
starting sequence. I just send sequence of bytes in OnClientConnect 
events of server socket - it seems to work fine without any problem.

Lukas

I'm using TWSocketServer to handle multiple incoming connections from 
a client's embedded unit.


Unfortunately the remote unit has a few limitations; the main one 
being that it can establish
an IP connection to a server but cannot send data until the server 
requests it.


This means that although the OnClientConnect function gets called, 
the OnDataAvailable does not.


I had put a line of code in the OnClientConnect to trigger the 
OnDataAvailable function

but this seems to be blocking other connections.


You should not do that. OnDataAvailable is triggered when the other 
side has sent data.



My questions are:-
i)Is there a way to trigger the OnDataAvailable 
function by post a message on the socket.


No way. Well, no way that has real meaning.

ii)   Is there a better way to do this without going 
to a threaded model.


No need to go multithreaded. You said: cannot send data until the 
server requests it. This is the solution: once the embedded unit is 
connected send the request it waits. Probably the banner property is 
the place where you could place you request because banner is what the 
server component sent immediately when a client connect.


BTW and for my information, what kind of unit is this and what kind of 
request does it needs ?


--
francois.pie...@overbyte.be
The author of the freeware multi-tier middleware MidWare
The author of the freeware Internet Component Suite (ICS)
http://www.overbyte.be

--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be




--
lukas skala
envinet a.s.
divize projektu a inzenyringu (project and engineering division)
modrinova 1094
674 01 trebic

tel: +420 568 409 862 (811)
fax: +420 568 409 875
gsm: +420 724 461 062
icq: 66842878
eml: lukas.sk...@envinet.cz, luky.sk...@gmail.com
www: http://envinet.cz




--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be