TCPListener and TCPClient same port issue.

E

Erik

getting a "10048: Only one usage of each socket address
(protocol/network address/port) is normally permitted." exception.
When I attempt sending a message to myself.

I start a thread to listen on port 6500 and then in the main thread I
try connecting and sending data. The listener works or at least
doesn't throw an exception. When I try sending myself a message I get
the error.

I have done similar thing's in C.. I created a proxy server and the
concept is identical. Listen on xxx port then send the data to
another machine on the same port.

What is going on? This has to work cause else I would not be allowed
to open IE while IIS is running!

Thanks in advance!

(reply to the list because I have no e-mail access.)

Erik


Starting up a thread that Listens on port 6500 using TCPListener.

const int portNumber = 6500;
TcpListener tcpListener = new TcpListener(portNumber);

tcpListener.Start();

/* Block till connected */
TcpClient tcpClient = tcpListener.AcceptTcpClient();

/* got connected, do something */


In the main process thread, I attempt sending a message to myself.


TcpClient tcpClient = new TcpClient();
try{
tcpClient.Connect("127.0.0.1", 6500);
NetworkStream networkStream = tcpClient.GetStream();

Byte[] sendBytes = Encoding.ASCII.GetBytes("Is anybody
there");
networkStream.Write(sendBytes, 0, sendBytes.Length);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top