PDA

Click to See Complete Forum and Search --> : How to detect the socket's status of the remote side?


StormJason
May 14th, 2002, 03:32 AM
i am writting my own winsock component use the system.net namespace. i have done the connection, getdata and send data section. but when i try to write a property that allow user to retrieve the status of the connection... i stucked! i have a difficulty to acquire the status of the remote socket.. that means how i going to know the remote socket that connect to my socket is drop out or etc.. can someone give me any idea on how to do this. thanks

Cander
May 14th, 2002, 08:38 AM
you really just have to roll your own state property code. It is just a matter of setting it in your class to whatever value is appropriate when appropriate.

From some code I got, if the server receives data at 0 length then it is disconnected. It looked like this


Private Sub DoStreamReceive(ByVal ar As IAsyncResult)
Dim intCount As Integer

Try
SyncLock mobjClient.GetStream
intCount = mobjClient.GetStream.EndRead(ar)
End SyncLock
If intCount < 1 Then
' Socket has disconnected
Exit Sub
End If



I hope that helps you out