Wrappers to do full sendNetworkData and ReceiveNetworkData

Share your advanced PureBasic knowledge/code with the community.
Quin
Addict
Addict
Posts: 1132
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Wrappers to do full sendNetworkData and ReceiveNetworkData

Post by Quin »

idle wrote: Fri Mar 28, 2025 8:42 am I don't understand why your having trouble with the connection, it will just fail and return the error
I am using the functions in the server for both server and client via the reverse proxy and its not crashing
That's super interesting, I've had it crash for both my client and server. Using IsSocketAvailable provided by another forum member fixes it on the client side, but it doesn't work on the server side. The line that's failing is always:

Code: Select all

SendLen = SendNetworkData(ClientID, *Buffer + TotalSent, TryLen)
Saying the specified connection ID is null.
IMO this should not be a crash on the PB side, that's frankly absurd. Just return a suitable error value. Here's hoping for NetworkError() in 6.30 ;)
User avatar
idle
Always Here
Always Here
Posts: 5884
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Wrappers to do full sendNetworkData and ReceiveNetworkData

Post by idle »

I think you'll find it's how your using them is the problem
User_Russian
Addict
Addict
Posts: 1522
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: Wrappers to do full sendNetworkData and ReceiveNetworkData

Post by User_Russian »

I see that they are improving the network functions here.
Does anyone have an analogue of function OpenNetworkConnection() with non-blocking mode for TCP? I have it for older versions of PB (without IPv6) and only for Windows.
Quin
Addict
Addict
Posts: 1132
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Wrappers to do full sendNetworkData and ReceiveNetworkData

Post by Quin »

idle wrote: Mon Mar 31, 2025 7:18 pm I think you'll find it's how your using them is the problem
Would you mind expanding on what you mean here? How is it possible to use these functions "incorrectly"?
User avatar
idle
Always Here
Always Here
Posts: 5884
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Wrappers to do full sendNetworkData and ReceiveNetworkData

Post by idle »

I don't know how you're using them but the functions aren't the problem here. If you need some help ask a question If you want ro see how I'm using them look at the source of atomic webserver.
Quin
Addict
Addict
Posts: 1132
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Wrappers to do full sendNetworkData and ReceiveNetworkData

Post by Quin »

I did ask a question, how to check for a valid client ID. The IsSocketAvailable procedure seemed to work on the client-side but not on the server, it would always return false for any client.
I really don't see how a PB function crashing in your procedure could be my fault, but I also see how it's definitely not yours, so I'll just hope for a native NetworkError function in the meantime.
User avatar
idle
Always Here
Always Here
Posts: 5884
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Wrappers to do full sendNetworkData and ReceiveNetworkData

Post by idle »

Considering both functions are only used in the circumstances of network events connect or event data the question is how do they fail. In both cases you have valid connections.

I agree it would be nice to have a test to see if the socket is open but it's not so easy.
Quin
Addict
Addict
Posts: 1132
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Wrappers to do full sendNetworkData and ReceiveNetworkData

Post by Quin »

idle wrote: Tue Apr 01, 2025 9:16 pm Considering both functions are only used in the circumstances of network events connect or event data the question is how do they fail. In both cases you have valid connections.
no, you don't.
What if the server drops? What if the user loses internet connectivity? Etc etc? These are things I see happen in the real world in my app, and when it does, sometimes invalid client ID's get passed to this function. PB definitely shouldn't just barf like this and crash, though.
User avatar
idle
Always Here
Always Here
Posts: 5884
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Wrappers to do full sendNetworkData and ReceiveNetworkData

Post by idle »

Quin wrote: Tue Apr 01, 2025 10:55 pm
idle wrote: Tue Apr 01, 2025 9:16 pm Considering both functions are only used in the circumstances of network events connect or event data the question is how do they fail. In both cases you have valid connections.
no, you don't.
What if the server drops? What if the user loses internet connectivity? Etc etc? These are things I see happen in the real world in my app, and when it does, sometimes invalid client ID's get passed to this function. PB definitely shouldn't just barf like this and crash, though.
if the server drops while your in a send or receive it will detect it but it won't if your missing a #PB_NetworkEvent_Disconnect event. If your still having issues ask a question with a code example of your client and server.
Network code can be frustrating to debug, it should be as simple as writing to a file but it's not.
Quin
Addict
Addict
Posts: 1132
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Wrappers to do full sendNetworkData and ReceiveNetworkData

Post by Quin »

Idle,
You're absolutely right, it was completely a bug on my side. I wasn't assigning my users their correct client IDs! :oops: :oops:
Your functions work great, thanks for sharing!
User avatar
idle
Always Here
Always Here
Posts: 5884
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Wrappers to do full sendNetworkData and ReceiveNetworkData

Post by idle »

Quin wrote: Fri Apr 11, 2025 11:42 pm Idle,
You're absolutely right, it was completely a bug on my side. I wasn't assigning my users their correct client IDs! :oops: :oops:
Your functions work great, thanks for sharing!
Glad you found the bug.
Quin
Addict
Addict
Posts: 1132
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Wrappers to do full sendNetworkData and ReceiveNetworkData

Post by Quin »

Hey Idle,
Can't use these functions on Linux...
With the asm backend I get:
Line 110 - __errno_location() is not a function, array, list, map or macro.
and with the C backend, I get:
Line 118 - Constant not found: #WSA_IO_INCOMPLETE.
It's maybe obvious from the errors themselves, but my line numbers are different, so it's in the NetworkErrorContinue function.
User avatar
idle
Always Here
Always Here
Posts: 5884
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Wrappers to do full sendNetworkData and ReceiveNetworkData

Post by idle »

I don't know if there are equivalents to #WSA_IO_INCOMPLETE or #WSA_IO_PENDING on linux
they're currently out of the compiler if and as for the errno it probably needs an ImportC like

Code: Select all

ImportC ""
__errno_location() 
EndImport   
error = PeekI(__errno_location()) 
I'll be switching over to Linux in the next couple of days.
Quin
Addict
Addict
Posts: 1132
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Wrappers to do full sendNetworkData and ReceiveNetworkData

Post by Quin »

Idle,
That import didn't work unfortunately, but I'm normally using the C backend, so it doesn't bother me too much.
As for the constants, I think you'd want something like EAGAIN or EWOULDBLOCK, but you're far more knowledgeable about this than me, so I'll await your thoughts once trying linux :D
Quin
Addict
Addict
Posts: 1132
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Wrappers to do full sendNetworkData and ReceiveNetworkData

Post by Quin »

Hey Idle,
Any updates? I'd really like to run my server on Linux :D
Thanks for all your ggreat work and your talent!
Post Reply