Only one usage of each socket address (protocol/network address/port) is normally permitted




Hi. I am getting the below error:


Event Type: Error
Event Source: PeskyService
Event Category: None
Event ID: 0
Date: 1/30/2008
Time: 5:49:10 PM
User: N/A
Computer: Computer
Description:
Only one usage of each socket address (protocol/network address/port)
is normally permitted


The service is starting (successfully) and then throwing this error
immediately after. It does this about 1,900 times in a very short
period of time and then throws an event log too full error.

I am not closing something when I should be - I feel. I have provided
the relevant methods (I think) showing where stuff gets opened and
closed.

The methods are:

protected override void OnStart(string[] args)
{
this.timer1.Enabled = true;
new Thread(new ThreadStart(Listen)).Start();

}

protected override void OnStop()
{
this.timer1.Enabled = false;
base.OnStop();

}


public void Listen()
{

Queue unsyncq = new Queue();
connectionQueue = Queue.Synchronized(unsyncq);

try
{

TcpListener listener = new TcpListener(_telnetServer,
_telnetPort);
listener.Start();

while (true)
{

_telnetSocket = listener.AcceptTcpClient();
connectionQueue.Enqueue(_telnetSocket);

Thread workingthread = new Thread(new
ThreadStart(TheConnectionHandler));
workingthread.Start();

}

}
catch (Exception e)
{
eventLog2.WriteEntry("Error in Listener:" + e.Message,
EventLogEntryType.Error);
return;
}

}

....


public void TheConnectionHandler()
{

_telnetSocket = (TcpClient)connectionQueue.Dequeue();
_clientStream = _telnetSocket.GetStream();

while (true)
{

_bytesRead = 0;

try
{

_bytesRead = _clientStream.Read(message, 0,
4096); //message

}
catch
{
//a socket error has occured
break;
}
if (_bytesRead == 0)
{
break;
}

statusMessage += ASCII.GetString(message, 0,
_bytesRead);

[SNIP]

_telnetSocket.Close();
_clientStream.Close();
}
.



Relevant Pages

  • RE: Only one usage of each socket address (protocol/network address/po
    ... another connection has already been accepted... ... Only one usage of each socket address ... protected override void OnStop() ... TcpListener listener = new TcpListener(_telnetServer, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: MultiPage Expert Please (Dynamic MultiPage controls)
    ... MultiTabCompositeControl tab; ... public void Button1_Click{ ... protected override void CreateChildControls() { ... I created a composite control class along ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: Binding a Collection as a component
    ... public int IndexOf ... public void Remove ... protected override void OnSetComplete(int index, object oldValue, object ... public bool SupportsChangeNotification ...
    (microsoft.public.dotnet.general)
  • Re: PDA Graphics - Flicker Free.
    ... "Keith Welch" wrote: ... >> private System.Windows.Forms.Timer timer; ... >> protected override void OnPaint ... >> public void BeginScene() ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Newbie:Extending an Image Button
    ... > public class OnOffImageButton: System.Web.UI.WebControls.ImageButton ... > public void TurnOff() ... > protected override void LoadViewState ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)

Loading