Q: Socket class - disconnect notify??

  • Thread starter Thread starter HABJAN ®iga
  • Start date Start date
H

HABJAN ®iga

Is there a way to be notifyed (callback, event,...) when the connection of
socket was closed... The WinSock activex in vb6 had event ondisconnect...

I get exception when i try to send some data, but i need disconnect info
sooner.

I have a solution with timer that checks the state of socket, but i don't
like to use timers...

best re,
habix
 
If you have a pending read waiting on the Socket, it will fail with an
exception when the socket is closed. That should give you more timely
notification about the disconnection.
 
Thanks for response Will,

I found a sample class, that uses frameworks socket class and exports itself
with events and methods like WinSock.ocx in VB6. I looked up how the
disconnect event was raised:

The class uses async callbacks for reading the data, and when you call
EndReceive function on callback, the return value is BytesRead. If you get 0
bytes, the disconnect event is raised.

best re,
habix
 
Is there a way to be notifyed (callback, event,...) when the connection of
socket was closed... The WinSock activex in vb6 had event ondisconnect...

I get exception when i try to send some data, but i need disconnect info
sooner.

I have a solution with timer that checks the state of socket, but i don't
like to use timers...

best re,
habix

You should catch and handle the exception (fire your own event if you
need to). You will also note that a socket can be closed _during_ a
send or read operation. In fact, you should handle all exceptions.

Rgds,
 
Back
Top