Page 1 of 1

Question About Network Clients

Posted: Fri Mar 31, 2006 3:38 am
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

Posted: Thu Apr 06, 2006 7:12 pm
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.