isConnected(Socket)

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

isConnected(Socket)

Post 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.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Why don't you process the #PB_NetworkEvent_Disconnect event?
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

Because that even is only fired when the client disconnects from the server. Not when the server disconnects the client.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

The server program should not keep track of the connection id of a connection it just closed.
Jan Vooijs
Enthusiast
Enthusiast
Posts: 196
Joined: Tue Sep 30, 2003 4:32 pm
Location: The Netherlands

Post 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

Code: Select all

#PB_NetworkEvent_Disconnect 
see the manual under:

Code: Select all

CloseNetworkConnection(Connection)
again.

Hope this helps.

Jan V.
Life goes to Fast, Enjoy!!

PB 4 is to good to be true, wake up man it is NOT a dream THIS is a reality!!!

AMD Athlon on 1.75G, 1Gb ram, 160Gb HD, NVidia FX5200, NEC ND-3500AG DVD+RW and CD+RW, in a Qbic EO3702A and Win XP Pro SP2 (registered)
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post 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.
Jan Vooijs
Enthusiast
Enthusiast
Posts: 196
Joined: Tue Sep 30, 2003 4:32 pm
Location: The Netherlands

Post 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.
Life goes to Fast, Enjoy!!

PB 4 is to good to be true, wake up man it is NOT a dream THIS is a reality!!!

AMD Athlon on 1.75G, 1Gb ram, 160Gb HD, NVidia FX5200, NEC ND-3500AG DVD+RW and CD+RW, in a Qbic EO3702A and Win XP Pro SP2 (registered)
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

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