473,611 Members | 2,236 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Ena bled = true;
new Thread(new ThreadStart(Lis ten)).Start();

}

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

}
public void Listen()
{

Queue unsyncq = new Queue();
connectionQueue = Queue.Synchroni zed(unsyncq);

try
{

TcpListener listener = new TcpListener(_te lnetServer,
_telnetPort);
listener.Start( );

while (true)
{

_telnetSocket = listener.Accept TcpClient();
connectionQueue .Enqueue(_telne tSocket);

Thread workingthread = new Thread(new
ThreadStart(The ConnectionHandl er));
workingthread.S tart();

}

}
catch (Exception e)
{
eventLog2.Write Entry("Error in Listener:" + e.Message,
EventLogEntryTy pe.Error);
return;
}

}

....
public void TheConnectionHa ndler()
{

_telnetSocket = (TcpClient)conn ectionQueue.Deq ueue();
_clientStream = _telnetSocket.G etStream();

while (true)
{

_bytesRead = 0;

try
{

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

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

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

[SNIP]

_telnetSocket.C lose();
_clientStream.C lose();
}
Jan 30 '08 #1
9 38053
This normally happens when a client tries to connect on a socket on which
another connection has already been accepted...

"pbd22" wrote:
>
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.Ena bled = true;
new Thread(new ThreadStart(Lis ten)).Start();

}

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

}
public void Listen()
{

Queue unsyncq = new Queue();
connectionQueue = Queue.Synchroni zed(unsyncq);

try
{

TcpListener listener = new TcpListener(_te lnetServer,
_telnetPort);
listener.Start( );

while (true)
{

_telnetSocket = listener.Accept TcpClient();
connectionQueue .Enqueue(_telne tSocket);

Thread workingthread = new Thread(new
ThreadStart(The ConnectionHandl er));
workingthread.S tart();

}

}
catch (Exception e)
{
eventLog2.Write Entry("Error in Listener:" + e.Message,
EventLogEntryTy pe.Error);
return;
}

}

....
public void TheConnectionHa ndler()
{

_telnetSocket = (TcpClient)conn ectionQueue.Deq ueue();
_clientStream = _telnetSocket.G etStream();

while (true)
{

_bytesRead = 0;

try
{

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

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

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

[SNIP]

_telnetSocket.C lose();
_clientStream.C lose();
}
Jan 31 '08 #2
OK, thanks.
I sort of figured that but am unclear where exactly to post the stop
command.
If I do something like the below, the intllisense tells me that
listener.stop() will
never be reachable. Where, exactly, do i call stop??

Thanks.
TcpListener listener = new TcpListener(_te lnetServer,
_telnetPort);
listener.Start( );

while (true)
{

_telnetSocket = listener.Accept TcpClient();
connectionQueue .Enqueue(_telne tSocket);

Thread workingthread = new Thread(new
ThreadStart(The ConnectionHandl er));
workingthread.S tart();

}
listener.Stop() ;
Jan 31 '08 #3
anybody care to address the OP? :)

Should I be flusing my queue and closing the listener?
If so, where exactly should I be placing my closing logic?

I'd appreciate any help here. Thanks!
Jan 31 '08 #4
On Thu, 31 Jan 2008 06:12:10 -0800, pbd22 <du*****@gmail. comwrote:
OK, thanks.
I sort of figured that but am unclear where exactly to post the stop
command.
If I do something like the below, the intllisense tells me that
listener.stop() will
never be reachable. Where, exactly, do i call stop??
Where you call it now would be fine, if you had any way to exit the loop.
So, one fix is to change the loop so there's a way to exit it. :)

Personally, I wouldn't bother with the loop. I'd use the asynchronous API
so that I didn't have a thread sitting blocked at a call to an Accept
method, and thus I could stop and close the socket wherever I like without
worrying about some thread that I needed to coordinate with.

But barring that, another alternative would be to put a try/catch around
the call to AcceptTcpClient () and then just stop the listening socket from
somewhere else when you need to shut down the service. Then you catch the
exception that's thrown when the socket is stopped and closed, and in that
way detect that it's time to exit the loop (of course, in that scenario
there's no need to call Stop() after the loop, since calling Stop() and
Close() would be what got you out of the loop in the first place :) ).

Pete
Feb 1 '08 #5
Thanks Pete.

So, something like this?

TcpListener listener = new TcpListener(_te lnetServer, _telnetPort);
listener.Start( );

while (true)
{
try
{
_telnetSocket = listener.Accept TcpClient();
}
catch (Exception)
{
break;
}
finally
{
connectionQueue .Enqueue(_telne tSocket);
Thread workingthread = new Thread(new
ThreadStart(The ConnectionHandl er));
workingthread.S tart();
}

}

And, elsewhere in the program, when it is time to exit, i call:

_telnetSocket.C lose()?

Thanks again,
Peter
Feb 1 '08 #6
On Fri, 01 Feb 2008 09:37:58 -0800, pbd22 <du*****@gmail. comwrote:
Thanks Pete.

So, something like this?
No, definitely not. The "finally" clause will _always_ execute, whether
an exception occurs or not. You don't want to go starting up a new client
connection thread if AccepTcpClient( ) throws an exception.

So, skip the "finally" clause...just leave that code outside the try/catch
block, and leave the "break" in the "catch" clause so that the loop exits
when an exception is thrown.

Pete
Feb 1 '08 #7
Pete:

What exactly am I doing wrong here?

Cannot access a disposed object.
Object name: 'System.Net.Soc kets.NetworkStr eam'.

I pretty easy stab is that I have closed my network stream and i am
trying to open it again.
What I don't get is that the prior connection closed everything and
the next user has to log on again (telnet 192.22.23.4).
So, shouldn't the new session open the stream as it always does?

Peter
Feb 1 '08 #8
Thanks.

I think the "refreshed data" may be my problem. How do I ensure that,
on the next
connection, the buffer is clean and that no "old" data will be
processed?

For what it is worth, If something goes bad in my program (either via
user logic or program error) this is
what i use:

private void SendResponse(st ring message)
{

//add some message to the buffer here...

_clientStream.W rite(buffer, 0, buffer.Length);
loginState = LoginState.Logi n;
_telnetSocket.C lose();

}
Here is my handler that sets up the connection

public void TheConnectionHa ndler()
{

_telnetSocket = (TcpClient)conn ectionQueue.Deq ueue();
_clientStream = _telnetSocket.G etStream();

buffer = ASCII.GetBytes( " ");
_clientStream.W rite(buffer, 0, buffer.Length);
_clientStream.F lush();

while (true)
{

_bytesRead = 0;

try
{

//blocks until a client sends a message
_bytesRead = _clientStream.R ead(message, 0,
4096); //message

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

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

// and so on...

PS. "I pretty easy stab = A pretty easy stab". Was typing fast.
Feb 1 '08 #9
Yeah, its the statusMessage variable.

Its not clean when a new connection happens.

A clean version is:

statusMessage = <x><y></y><z></z></x>

When the error happens, statusMessage reads:

statusMessage = <x><y></y><z></z></x><

the last "<" must have carried over from the former connection.

How do I make sure this doesn't happen?

Thanks.
Peter

Feb 1 '08 #10

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

Similar topics

0
1407
by: Josh | last post by:
I'm getting an error I dont understand. Here is the output: Content-Type: text/html Traceback (most recent call last): File "C:\PROGRA~1\APACHE~1\APACHE2\CGI-BIN\test.py", line 12, in ? s.connect( host, port ) File "<string>", line 1, in connect TypeError: connect() takes exactly one argument (2 given) Here is the code:
1
3784
by: Daniel | last post by:
after opening socket, sending data then closing socket 3000 times i get "Only one usage of each socket address" what am i doing wrong? is there some thing else i need to do to free up the socket after i send data into it? I simply want to open socket, send data, close socket and have the server just handle one client thread to recieve connection, recieve data, and close socket
0
2833
by: Alphamacaroon | last post by:
All, I'm wondering if anyone can help me with a strange problem I'm having. First off, here's what I'm trying to do: I'm developing a UDP network application that should allow the end user to choose the network interface they want to send and receive UDP packets on. Simple enough. If the computer has a single network card and IP address this all works
3
2488
by: Fredric Ragnar | last post by:
Hi, I am making a prototype system with Remoting in the bottom of the system. An XML Web Service is using the remote object on an IIS to present data. I am using a TcpChannel for communicating between the XML Web Service and the host for the remote object. Within the host a port is defined and the channel registered. It starts listening for requests. The destination port is therefore clearly defined.
2
13668
by: Beemer Biker | last post by:
I have an app that binds to 5003 and 5004. It works fine on a desktop VS2005/sp1 dotnet 2. It will not run on a laptop VS2005/sp1 dotnet 2 giving the above error on the very first bind. I cannot spot what is causing the problem. There is something different about the laptop no? Both system have xp, sp2 with latest patches and firewall off. The program should behave the same. I start guessing and disable spampal, snagit, whatever I...
2
1915
by: yogesh | last post by:
i developing a game in c++, for that i got the socket program is working successfull in freebsd , but the same program is shifted to the Redhat linux 9.0 . i change the ip address and the port is also same i can compile the code successfull. but if i run the server socket file It not assigning the port , the port i am liking is 8002 .
0
3115
by: jkhan | last post by:
Hi! I have problem which I shown in title and below as well. I have a Form name as Cancelation. The clientThread2() method is called on Form Load if I Close the Form and want to reload then the above error is generated as I tried to close, shutdown etc for closing the socket or thread but useless. Any one have idea about it. The above error is generated when it reached to this line ==> sender = new IPEndPoint(IPAddress.Any, 0); as I...
1
2536
by: =?Utf-8?B?Um9kcmlnbyBHYXJjw61h?= | last post by:
I have a client making web service calls to a NLB cluster. When the cluster was comprised by two machines everything went fine serving near two hundred service requests per second. Now I increased the number of machines in the NLB to four and I started getting Socket Exceptions related to 'Only one usage of each socket address'. I already checked the TcpTimedWaitDelay and MaxUserPorts in the registry so I don't think the problem is related...
1
5767
by: sdbranum | last post by:
For those who have found it impossible to get help in communicating with Wasp's WDT-2200 Barcode Scanner through a COM Port, except by using their supplied DTComm software, I am presenting what I have found through use of a Protocol Analyzer connected to the COM port, and how I have managed to upload (from Scanner to Computer) a file holding transactions recorded by others using the scanner to "Issue Parts". Quickly though, allow me to note...
0
8149
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8097
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8240
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7038
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6072
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5527
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4042
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2546
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1692
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.