473,387 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Q: Socket class - disconnect notify??

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
Nov 20 '05 #1
3 1810
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.
"HABJAN ®iga" <habix[AT]intelcom[DOT]si> wrote in message
news:bn********@enews3.newsguy.com...
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

Nov 20 '05 #2
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

"William Armstrong" <wi********@SPAMcrowsnest-design.com> wrote in message
news:eI**************@TK2MSFTNGP12.phx.gbl...
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.
"HABJAN ®iga" <habix[AT]intelcom[DOT]si> wrote in message
news:bn********@enews3.newsguy.com...
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


Nov 20 '05 #3
On Thu, 23 Oct 2003 12:14:39 +0200, "HABJAN ®iga"
<habix[AT]intelcom[DOT]si> wrote:
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,

Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: DreJoh | last post by:
I've read many articles on the subject and the majority of them give the same solution that's in article 821625 on the MSDN website. I'm using the following code and when a the client disconnects...
4
by: Chris Tanger | last post by:
Context: C# System.Net.Sockets Socket created with constructor prarmeters Internetwork, Stream and TCP everything else is left at the default parameters and options except linger may be changed...
0
by: integragreg | last post by:
I apologize in advance if I am posting to the wrong group, but at least one of my questions is related to Platform Invoke in C#. I am using .NET Framework 1.1, and for improved performance, I...
2
by: Rene Sørensen | last post by:
We are 4 students working on a assignment, that our teacher gave use, normally we do this is C++, but the 4 of us, use C# more often that C++ so… We made a small games called reversi, now our job...
11
by: atlaste | last post by:
Hi, In an attempt to create a full-blown webcrawler I've found myself writing a wrapper around the Socket class in an attempt to make it completely async, supporting timeouts and some scheduling...
3
by: Cheryl | last post by:
Hi. I am having a problem on handling asynchronous sockets in C#. I implemented a pair of client and server sockets. The connection is ok when first connected. However, when I turned off the...
4
by: Adam Clauss | last post by:
A while back I posted regarding a problem we were having with one of our applications which was randomly crashing. Monitoring memory usage revealed a spike in nonpaged pool memory just prior to...
0
by: cmrhema | last post by:
Hi, We have an asynchronous server socket program, which works fine BUT, when due to some circumstances, I receive null data or blank data, the server goes to infinite loop Here is the code ...
21
by: puzzlecracker | last post by:
Problem: I send a lot of requests to the application (running on a different box, of course), and I receive back responses from the app . Below: socket corresponds to Socket socket=new...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.