Page 1 of 1
isConnected(Socket)
Posted: Sat Jul 15, 2006 6:50 pm
by Shannara
Currently, when a connection is closed on the other end, the Socket id is never set to 0. Therefore, the program can never tell whether the socket is still valid or not.
This is bad because when the server tries to close a client connection, it will always crash if the socket is no longer valid. And, currently, there is no way in PB to determine whether a socket is valid ...
It would be nice to have this command so that client connections can be safely closed on the server side without the server crashing.
Posted: Sat Jul 15, 2006 8:04 pm
by Trond
Why don't you process the #PB_NetworkEvent_Disconnect event?
Posted: Sat Jul 15, 2006 9:11 pm
by Shannara
Because that even is only fired when the client disconnects from the server. Not when the server disconnects the client.
Posted: Sat Jul 15, 2006 9:16 pm
by Trond
The server program should not keep track of the connection id of a connection it just closed.
Posted: Sun Jul 16, 2006 12:10 am
by Jan Vooijs
Shanara,
In the manual (help file) see:
Code: Select all
CloseNetworkConnection(Connection)
With that YOU (the server) can disconnect the client.
And the otherway when the client is disconnecting, you get an
see the manual under:
Code: Select all
CloseNetworkConnection(Connection)
again.
Hope this helps.
Jan V.
Posted: Sun Jul 16, 2006 2:05 am
by Shannara
Basically..
A client could disconnect anytime they want. It is entirely possible for the server to try to send data right before the the client disconnect event is raised. This happens quite often. And when it does, the server crashes ... so ...
If there was a way to determine if a connection is valid, then we could always check if the connection is valid before any network command.
Right now, the only thing the server can do is crash because there is no way to check if a connection is valid or not.
Posted: Sun Jul 16, 2006 1:28 pm
by Jan Vooijs
So keep a linked list (or array) where every 'valid' client is on. If an "#PB_NetworkEvent_Disconnect" fires get the client of the list an do not send anymore aka test just before any send comand to the client.
Second you need a timeout parameter for every send command so not to lockup your server the term used by you as 'crash' is something else. i bet the server is still running but out of sync with the client.
I believe there is an 'timeout' parameter in the beta section for the network commands (there is a recent post about this i think in the bugs section of the forum).
Jan V.
Posted: Sun Jul 16, 2006 4:29 pm
by Shannara
However, as mentioned above, twice, there is no way to test if it is a valid client. Just be cause it is on an array or linklist, doesnt make it valid as the disconnect event have been known to fire before a previous packet from the client have been sent.