.NET Framework Bookmark and Share   
 index > Network Class Library (System.Net) > Listen does not receive callback if cable disconnected and then subsequently connected
 

Listen does not receive callback if cable disconnected and then subsequently connected

This is in C#.

If i start a listen socket with the cable unconnected and then subsequently make physical connection ido not get a callback. I am forced to recall/create a new listen socket. This does work but i have a thread count increase everytime i create a new listen socket. I cannot seem kill/dispose a listen socket that never received a callback. What am i doing wrong or how do i resolve this problem?

example code below..

StartListener()
{

listener.Bind(localEP);

listener.Listen(1);

listener.BeginAccept(

new AsyncCallback(acceptCallback), listener);

state.listener = listener;

}

public
void acceptCallback(IAsyncResult ar)

{

Socket listener = (Socket)ar.AsyncState;

Socket handler = listener.EndAccept(ar); //EndAccept returns socket that can}

  •  
IMPACTdude

Make sure to invoke Close method for handler Socketand for listener Socket when you don't need them.

Oleksii Prokopchuk [NCL]

Make sure to invoke Close method for handler Socketand for listener Socket when you don't need them.

Oleksii Prokopchuk [NCL]
I have attempted to call listener.ShutDown() and listener.Close(). The both return exceptions even though listener is not null. Why would this be the case?
IMPACTdude
i need to also mention i am running on Compact Framework 2.1.
IMPACTdude
I have resolved the thread count increase by removing the call to .Shutdown() and only calling .Close(). However, i still get a lot of low level exceptions being thrown. Is there another step necessary prior to Close() which prevents throwing of exceptions. During the Close() process the listen callback even got called. It errored out because it was invalid but it did happen.
IMPACTdude
It is difficult to say why exactly you are getting exceptions without any trace information.

Ge a trace of your code using information here: http://ferozedaud.blogspot.com/2009/08/tracing-with-systemnet.html


feroze
--
My blog
Feroze Daud

You can use google to search for other answers

Custom Search

More Threads

• Downloading file but wrong data.
• SMTP Mail Error
• Force TLS using System.Net.SmtpClient
• how SocketEventAsyncArgs works
• .NET c# Sockets server
• How to develop pinging program?
• TcpClient: what happens when server thread killed by another process?
• Couldn't connect to remote server
• calculate the Round Trip Time
• System.Net.Mail SMTP Fails to Request Connection with Server