Puzzled by ReceiveNetworkData().

Everything else that doesn't fall into one of the other PB categories.
User avatar
idle
Always Here
Always Here
Posts: 6238
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Puzzled by ReceiveNetworkData().

Post by idle »

You may be looking for a #WSAECONNABORTED

If the connection gets dropped during a send or recieve this error will be reported as a -1 on the send or receive and you have to look up the last error, for windows a call to WSAGetLastError_() and in linux you just look at errno (if there's a way in PB way to read the current processes errno in linux) the error constants are more of less the same for compatibility with Berkley sockets.

Creating a thread per connection and using semaphores is the a reasonable compromise, even if you're transferring small amounts of data, the cost of a signal is minimal compared to spawning a thread per receive, though that may be appropriate if you're only dealing with large transfers.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Puzzled by ReceiveNetworkData().

Post by srod »

A good idea using semaphores. Yes, better than my signalling through a connection variable - though admittedly that works fine for my needs. Yes that would avoid the need for a delay as well.

Thanks for the tip Idle. :)
I may look like a mule, but I'm not a complete ass.
User avatar
idle
Always Here
Always Here
Posts: 6238
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Puzzled by ReceiveNetworkData().

Post by idle »

There's no issues doing that for receive though there are possibly some issues with a send thread as you have to get your data in to the thread and I'm not sure if you could run into any issues there or not.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Puzzled by ReceiveNetworkData().

Post by srod »

I am not using individual send/receive threads etc. The server simply spawns a new thread for each individual connection and then sends 'messages' to each thread as appropriate.
I may look like a mule, but I'm not a complete ass.
Post Reply