Page 1 of 1

Some trouble with NetworkEvents

Posted: Thu Sep 26, 2013 12:09 pm
by roleg
I'm writing a Client-Server application (5 clients and one server).

At some point in the test on localhost, after prolonged number of requests sents and received to/from server, the Clients one by one, for unknown reasons, issue #PB_NetworkEvent_Disconnect event. After that, the Server continues to process without any reaction and not registering the #PB_NetworkEvent_Disconnect.

Most interesting that on the Server side it get yet #PB_NetworkEvent_Disconnect, but only after I close Clients applications.

Image

Where is my omission?


PB 5.11

Re: Some trouble with NetworkEvents

Posted: Thu Sep 26, 2013 12:14 pm
by Bisonte
What do you think ?
How can someone help you to solve, without some code that demonstrate it ?

Re: Some trouble with NetworkEvents

Posted: Thu Sep 26, 2013 12:52 pm
by roleg
Bisonte wrote:What do you think ?
How can someone help you to solve, without some code that demonstrate it ?
standart code, from PB Help, only server event handler in thread

Re: Some trouble with NetworkEvents

Posted: Mon Sep 30, 2013 6:49 pm
by RichAlgeni
It's close to impossible to diagnose problems in code, without seeing that code. That being said, I will tell you what works best for me. This is for Windows only, but I would imagine there is a similar code for other platforms.

Always use EnableExplicit.

Continue to interrogate NetworkServerEvent(), but ignore everything except for #PB_NetworkEvent_Connect.

Get the socket handle for each connection: socketHandle = ConnectionID(connectNumber). You can get the handle just once for each socket, and save it to a variable.

Use the Windows API: result = ioctlsocket_(socketHandle, #FIONREAD, @length).

If result <> 0, there was a socket error. Windows will handle the closing of the socket.

If length > 0, there is data to be read from the socket, otherwise there is nothing to be read.