Results 1 to 2 of 2

Thread: How to detect the socket's status of the remote side?

  1. #1

    Thread Starter
    Member
    Join Date
    May 2002
    Location
    Malaysia
    Posts
    45

    How to detect the socket's status of the remote side?

    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

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    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

    Code:
    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
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width