Page 1 of 1
Closing the connection server
Posted: Wed Nov 30, 2011 1:20 pm
by User_Russian
As an Internet client (connection open function OpenNetworkConnection ()), may determine that the connection was broken server?
I have used this method:
Code: Select all
DisableDebugger
Test=0
SendNetworkData(Connect, @Test, 0)
Err = WSAGetLastError_()
EnableDebugger
If Err
*Mem = AllocateMemory(1024)
If *Mem
FillMemory(*Mem, 1024, 0)
Test=FormatMessage_(#FORMAT_MESSAGE_FROM_SYSTEM, 0, Err, 0, *Mem, 1024, 0)
If Err>0
ErrorText.s = PeekS(*Mem, Test)
EndIf
FreeMemory(*Mem)
EndIf
EndIf
It works, but only for TCP connections.
And if you use UDP, then not working properly.
How to verify that the server connection is broken?
Re: Closing the connection server
Posted: Thu Dec 01, 2011 1:54 am
by RichAlgeni
Try using the windows API function
ioctlsocket. If there is no error,
length will return the number of bytes available to be read.
Code: Select all
Define length
Define result
Define socketHandle.i
; make sure the socket is still valid
socketHandle = ConnectionID(Connect)
result = ioctlsocket_(socketHandle, #FIONREAD, @length)
If result < 0; socket error
ProcedureReturn result
EndIf
Re: Closing the connection server
Posted: Mon Dec 05, 2011 12:52 pm
by kryptonn
RichAlgeni wrote:Try using the windows API function ioctlsocket.
I known that
User_Russian did not pay for PureBasic, uses the pirate copy, and spreads the pirate copies itself. He has not a moral right to get no support.
http://www.purebasic.fr/english/viewtop ... 02#p367802
Re: Closing the connection server
Posted: Mon Dec 05, 2011 4:35 pm
by AndyMK
User_Russian wrote:As an Internet client (connection open function OpenNetworkConnection ()), may determine that the connection was broken server?
I have used this method:
Code: Select all
DisableDebugger
Test=0
SendNetworkData(Connect, @Test, 0)
Err = WSAGetLastError_()
EnableDebugger
If Err
*Mem = AllocateMemory(1024)
If *Mem
FillMemory(*Mem, 1024, 0)
Test=FormatMessage_(#FORMAT_MESSAGE_FROM_SYSTEM, 0, Err, 0, *Mem, 1024, 0)
If Err>0
ErrorText.s = PeekS(*Mem, Test)
EndIf
FreeMemory(*Mem)
EndIf
EndIf
It works, but only for TCP connections.
And if you use UDP, then not working properly.
How to verify that the server connection is broken?
You should google UDP and learn as much as you can about it before posting such questions. UDP is a connectionless protocol. When you send a packet of data, you have no way of knowing if the packet got there unless you program that functionality in to it. Detecting a disconnect over UDP is something you have to program yourself.