Detect invalid Connection ID prior

Just starting out? Need help? Post your questions and find answers here.
danny88
User
User
Posts: 38
Joined: Sun Jan 21, 2024 8:13 am

Detect invalid Connection ID prior

Post by danny88 »

hello

look at this code :

Code: Select all

ClientID = 750154536	;Random invalid Connection ID

sent = SendNetworkString(ClientID, "Hello"); Returns Invalid memory accesss
How to check if Connection ID is valid before using it
infratec
Always Here
Always Here
Posts: 7581
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Detect invalid Connection ID prior

Post by infratec »

TCP or UDP ?
In UDP this should not happen.

Do you send data regulary or with pauses? (How long are the pauses?)

In general you can not detect this with PB internal commands directly.
You can try to keep the connnection alive to avoid this, by sending periodically 'keep-alive' packets.

I'm not sure if you can detect via low level functions if a connection which was opened by PB can be checked.
danny88
User
User
Posts: 38
Joined: Sun Jan 21, 2024 8:13 am

Re: Detect invalid Connection ID prior

Post by danny88 »

TCP.
I send packets periodically
There are many clients that connect and disconnect randomly.

So it may happen that the client is connected when the decision is taken to send it a packet but then discconnects just before the packet is sent
infratec
Always Here
Always Here
Posts: 7581
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Detect invalid Connection ID prior

Post by infratec »

Do you detect the disconnect event?

But ... in general I would say it is a PB bug.
The procedure should return -1 and should not generate an IMA.
danny88
User
User
Posts: 38
Joined: Sun Jan 21, 2024 8:13 am

Re: Detect invalid Connection ID prior

Post by danny88 »

yeah that's also what I think.
any idea how to overcome it ?
Gérard
User
User
Posts: 48
Joined: Sat Oct 17, 2015 6:00 pm
Location: France
Contact:

Re: Detect invalid Connection ID prior

Post by Gérard »

Code: Select all

OnErrorGoto(?ErrorHandler)

ClientID = 750154536	;Random invalid Connection ID

sent = SendNetworkString(ClientID, "Hello"); Returns Invalid memory accesss

ErrorHandler:
;Error handling
■ Win10 64-bit (Intel Celeron CPU N2920 @ 1.86GHz, 4,0GB RAM, Intel HD Graphics) & PB 6.00 LTS
■ Vivre et laisser vivre.
■ PureBasic pour le fun
■ cage sur le forum Français
■ Mes sites: http://pbcage.free.fr - http://yh.toolbox.free.fr
infratec
Always Here
Always Here
Posts: 7581
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Detect invalid Connection ID prior

Post by infratec »

infratec wrote: Thu Dec 26, 2024 10:59 am Do you detect the disconnect event?
Then you have to close the connection.
Post Reply