Results 1 to 3 of 3

Thread: Socket connected property

  1. #1

    Thread Starter
    Junior Member Cakkie's Avatar
    Join Date
    May 2002
    Location
    Olen, Belgium
    Posts
    24

    Socket connected property

    The socket class has a connected property. However, this doesn't seem to work... Once I connected, it always says connected, even if the server closed the connection.

    Is there another way to determine if a socket is still connected or not? I'm not using Async reads, so I cannot use that.

  2. #2
    Member
    Join Date
    May 2002
    Location
    Malaysia
    Posts
    45
    i also face the same problem, i have 1 soulution here but seems like is not a very good solution... hopefully is useful to you..

    * assume "my_socket" is a type of system.net.sockets.socket

    dim sckconnected as boolean

    private sub check_connection()
    dim Null_buf(0) as byte


    try
    Null_buf(0)=nothing
    my_socket.send(Null_buf)
    sckconnected=true
    catch
    sckconnected=false
    end try
    end sub

    if the socket on the remote side is close the line my_socket.send will generate an erorr and catch by the error handling. but the drawback of this method is the remote side will accept a 0x00 if it is connected to your socket. but you can further enchance it by setting a time out to call this function. that means for example if the socket is not receiving any data for 1 second, this sub routine will fire to poll the status of the socket...

  3. #3
    Junior Member
    Join Date
    Apr 2002
    Posts
    23

    Same problem here...

    The example you above dosent work if you use a VB6 Socket in the session. The remote (VB6) Socket sends an Close Socket request. But .NET Socket cant catch it. There for the connection need to timeout before getting Connection error when sending data.

    There must be a nother way to solv the problem.

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