PDA

Click to See Complete Forum and Search --> : Socket connected property


Cakkie
May 28th, 2002, 06:50 AM
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.

StormJason
May 29th, 2002, 01:47 AM
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...

[SPS]dEFiNE
Jun 10th, 2003, 09:54 AM
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.:eek: