Question About Network Clients

Linux specific forum
Alex
User
User
Posts: 41
Joined: Fri Aug 19, 2005 8:14 pm

Question About Network Clients

Post by Alex »

I have a client program, essentially the same as in the PB example, but I need to know how to make it stop listening if the server dies during the connection, or the server is being extremely slow? Can someone fill in the blanks for me?

Code: Select all

ConnectionID = OpenNetworkConnection("127.0.0.1", Port)
   If ConnectionID
      SendNetworkString(ConnectionID,CLIENT_VALIDATION_STRING$)

; Here is where I need the help. If the server dies before I
; receive my data, how do I know? Can I set a
; timeout somehow, or is there a Linux thing I can check?

      RESULT=ReceiveNetworkData(ConnectionID, *Buffer, 100)
      F00$=PeekS(*Buffer)
   Else
     End
   EndIf
Thanks in advance,

Alex
"How is it possible to bring order out of memory? I should like to begin at the beginning, patiently, like a weaver at his loom. I should like to say, 'This is the place to start, there can be no other.'

-Beryl Markham
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

For the dying part, I cannot help. But for the slowness part. You could try a vairant of what they did for IRC. Send a "ping" type packet and record when you sent it. Code the server in such a way to instantly respond to such packets. When you recieved that response, check the time difference. If it is over a certain amount of time, disconnect.

Or, while waiting for the response packet, keep a timer running, if the time is over a certain amount, close server connection.

I do not know if the above helps you any, but I hope so.
Post Reply