The woes of PureBasic's networking library
Posted: Thu Jun 05, 2025 3:52 pm
Hi,
First, I want to say I deeply respect the work that’s gone into PureBasic. It’s an incredible tool that’s stood the test of time, and I really admire what Fred has built, especially as a solo developer. It handles many things very well. Even when some features are missing (like setting/clearing selection in StringGadgets), there are often easy workarounds via the API, so that’s not a huge issue.
That said, after over a year of working with the networking library, I’ve found it to be one of the weakest parts of PB. It feels like a leaky abstraction over sockets, and I’ve run into many challenges:
In my own case, I’ve been maintaining a peer-to-peer chat app for a small group of blind friends (around 10 users). After literally a year of trying to work around the networking libraries' limitations, I ended up rewriting the server part in Go, PB just wasn’t viable for it and kept crashing in weird places due to invalid client IDs in some rare cases and I couldn't GDB it thanks to -ds being broken.
So while I think PB is excellent for many things (especially GUI and quick tooling), I can’t currently recommend it for projects that heavily depend on networking. I truly hope this area sees some love in future releases, and I’d love to return to using PB for this kind of work if that happens.
First, I want to say I deeply respect the work that’s gone into PureBasic. It’s an incredible tool that’s stood the test of time, and I really admire what Fred has built, especially as a solo developer. It handles many things very well. Even when some features are missing (like setting/clearing selection in StringGadgets), there are often easy workarounds via the API, so that’s not a huge issue.
That said, after over a year of working with the networking library, I’ve found it to be one of the weakest parts of PB. It feels like a leaky abstraction over sockets, and I’ve run into many challenges:
- The API is quite different from how most socket libraries do it, and it doesn’t use select, so you have to Delay(1) in your main loop, which can introduce latency.
- ReceiveNetworkData returns -2 in some cases, namely when trying to make it work with an nginx proxy for TLS without needing to implement key rotation with UseNetworkTLS, although the docs only mention -1.
- There’s no NetworkError() function, though I know Fred has expressed interest in adding one.
- There’s also no way to check if a client ID is valid (something like IsSocket() or IsNetworkConnection()), which can lead to crashes from invalid IDs.
- and so on...
In my own case, I’ve been maintaining a peer-to-peer chat app for a small group of blind friends (around 10 users). After literally a year of trying to work around the networking libraries' limitations, I ended up rewriting the server part in Go, PB just wasn’t viable for it and kept crashing in weird places due to invalid client IDs in some rare cases and I couldn't GDB it thanks to -ds being broken.
So while I think PB is excellent for many things (especially GUI and quick tooling), I can’t currently recommend it for projects that heavily depend on networking. I truly hope this area sees some love in future releases, and I’d love to return to using PB for this kind of work if that happens.