I've always been curious of this, i know the server can just tell when a client disconnects, but is it possible for the client to tell if it has lost connection from the server without having to send any packets?
Thanks, Cad.
Check if the Network Connection still exists?
Check if the Network Connection still exists?
Pro-Gamer, Programmer, Pro-Grammer
Try to send any String to the server, when SendnetworkData() fails (returning -1), the connection might be interrupted.
PB 4.30
Code: Select all
onErrorGoto(?Fred)You can also imitate the FTP potocol, sending a "NOOP" every x minutes/seconds. if the server does not react, the connection is interrupted.
Info: The NOOP-command is for keeping alive a FTP connecetion. A client can send it to the server, but some servers ignore NOOP and close the conenction after X minutes of inactivity.
Info: The NOOP-command is for keeping alive a FTP connecetion. A client can send it to the server, but some servers ignore NOOP and close the conenction after X minutes of inactivity.
PB 4.30
Code: Select all
onErrorGoto(?Fred)@Cadex:
maybe following routine i wrote years ago could help you, if i understand you right...
maybe following routine i wrote years ago could help you, if i understand you right...
Code: Select all
; English forum:
; Author: MrVainSCL
; Date: 19. January 2003
;Here is a normal version:
; ------------------------------------------------------------
;
; PureBasic Win32 API - CheckInternetConnection - Example v1.0
;
; by MrVainSCL! aka Thorsten 19/Jan/2003 PB v3.51+
;
; ------------------------------------------------------------
;
If InternetGetConnectedState_(0, 0)
result$ = "Online"
Else
result$ = "Offline"
EndIf
;
MessageRequester("Are we connected to the Internet?","We are "+result$,0)
End
;
; ------------------------------------------------------------
;Here is a Procedure() version:
; ------------------------------------------------------------
;
; PureBasic Win32 API - CheckInternetConnection - Example v1.0
;
; by MrVainSCL! aka Thorsten 19/Jan/2003 PB v3.51+
;
; ------------------------------------------------------------
;
Procedure MyCheckInternetConnection()
If InternetGetConnectedState_(0, 0)
result = 1
Else
result = 0
EndIf
;
ProcedureReturn result
EndProcedure
;
; -------- Check if user is connected to internet --------
;
If MyCheckInternetConnection() = 1
state$ = "Online"
Else
state$ = "Offline"
EndIf
;
MessageRequester("Are we connected to the Internet?","We are "+state$,0)
End
va!n aka Thorsten
Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
@Vain:
Your Procedures shows the current internet connection state. He wants to know if his client is connected to the server.
I think the only way is to include a "ping" routine, which is the savest one. This is the way many other applications do. Just send a short message to the server and wait for answer. If no answer comes in, then time out your connection or try to reconnect.
Your Procedures shows the current internet connection state. He wants to know if his client is connected to the server.
I think the only way is to include a "ping" routine, which is the savest one. This is the way many other applications do. Just send a short message to the server and wait for answer. If no answer comes in, then time out your connection or try to reconnect.
Tranquil

