Some trouble with NetworkEvents

Just starting out? Need help? Post your questions and find answers here.
roleg
User
User
Posts: 51
Joined: Wed Feb 24, 2010 2:07 pm

Some trouble with NetworkEvents

Post 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
User avatar
Bisonte
Addict
Addict
Posts: 1305
Joined: Tue Oct 09, 2007 2:15 am

Re: Some trouble with NetworkEvents

Post by Bisonte »

What do you think ?
How can someone help you to solve, without some code that demonstrate it ?
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
roleg
User
User
Posts: 51
Joined: Wed Feb 24, 2010 2:07 pm

Re: Some trouble with NetworkEvents

Post 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
User avatar
RichAlgeni
Addict
Addict
Posts: 935
Joined: Wed Sep 22, 2010 1:50 am
Location: Bradenton, FL

Re: Some trouble with NetworkEvents

Post 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.
Post Reply