473,385 Members | 1,372 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,385 software developers and data experts.

How to end a Socket.BeginAccept call

When closing down my server I get the following exception
An unhandled exception of type 'System.InvalidOperationException' occurred
in system.dll

Additional information: AcceptCallback
I beleive that it is the asynchronous BeginAccept call which causes the
problem. How can I avoid this? Here is the code:

private void ListenForClients()
{
listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp);
listener.Bind(new IPEndPoint(IPAddress.Any, 9123));
listener.Listen(10);

listener.BeginAccept(new AsyncCallback(this.OnAccept), listener);
Invoke(new UpdateEventListDelegate(UpdateEventList), new object[] {
"Listening for clients..." } );
}

private void radioButtonStopped_CheckedChanged(object sender,
System.EventArgs e)
{
if (radioButtonStopped.Checked == true)
{
Invoke(new UpdateEventListDelegate(UpdateEventList), new object[] {
"Closing server..." } );
listener.Close();
listeningThread.Abort();
Nov 17 '05 #1
2 4687
Is it not possible???

"Joachim" wrote:
When closing down my server I get the following exception
An unhandled exception of type 'System.InvalidOperationException' occurred
in system.dll

Additional information: AcceptCallback
I beleive that it is the asynchronous BeginAccept call which causes the
problem. How can I avoid this? Here is the code:

private void ListenForClients()
{
listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp);
listener.Bind(new IPEndPoint(IPAddress.Any, 9123));
listener.Listen(10);

listener.BeginAccept(new AsyncCallback(this.OnAccept), listener);
Invoke(new UpdateEventListDelegate(UpdateEventList), new object[] {
"Listening for clients..." } );
}

private void radioButtonStopped_CheckedChanged(object sender,
System.EventArgs e)
{
if (radioButtonStopped.Checked == true)
{
Invoke(new UpdateEventListDelegate(UpdateEventList), new object[] {
"Closing server..." } );
listener.Close();
listeningThread.Abort();

Nov 17 '05 #2
I Think You Have To unsubscribe all The subscribed values to the delegate By Using -= and then close it......it's Not Checked..But It hink so

From http://www.developmentnow.com/g/36_2...ccept-call.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
Mar 28 '07 #3

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

Similar topics

1
by: scott | last post by:
Hi all hope some one can help me with this prob because it is really annoying me and I can't seem to solve it. Just like to say thx to any one that can offer any help. Ok the prob. I have a...
1
by: Chris Morse | last post by:
WARNING: Verbosity: skip to the very bottom paragraph for succinct version of my question.) Hi- I can't seem to find an answer to this. I am playing around with a variation of the ".NET...
3
by: O.B. | last post by:
When sharing a Socket between threads, are the socket operations automatically synchronized to support multithreading? For example: Thread1 sets up a server socket to listen and invokes...
1
by: =?Utf-8?B?aXdkdTE1?= | last post by:
Hi, i have a socket that i use to listen for a connection. there can be any number of connections. when testing my socket, it sees the first connection, then no others. i call the BeginAccept()...
2
by: darthghandi | last post by:
I am trying to pass a socket object when an event is signaled. I have successfully bound to a network interface and listened on a port for incoming connection. I have also been able to accept...
5
by: darthghandi | last post by:
I've created a class to listen to all interfaces and do a BeginAccept(). Once it gets a connection, it passes the connected socket off and stores it in a List. Next, it continues to listen for...
14
by: =?Utf-8?B?TWlrZVo=?= | last post by:
I have a sync socket application. The client is blocked with Socket.Receive(...) in a thread, another thread calls Socket.Close(). This unblock the blocked thread. But the socket server is still...
10
by: ThunderMusic | last post by:
Hi, I'm currently working with sockets. I accept connections using m_mySocket.Listen(BackLogCount); But when I want to stop listening, I shutdown all my clients and call m_mySocket.Close(), but it...
4
by: O.B. | last post by:
I have a socket configured as TCP and running as a listener. When I close socket, it doesn't always free up the port immediately. Even when no connections have been made to it. So when I open...
4
by: setiarakesh | last post by:
I have designed a socket Server and developed asynchronous server . It is working fine with 60 Clients which are connecting to ths Server running at Machine (2 GB RAM and OS is Windows 2003...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.