mike_d...

I am developing a chat programme using TcpListener and TcpClient..
In the server side form, I have two buttons one is "Start Listening",the other is "Stop Listening"..
Now the problem is :
when I re-enter the "Start Listening" button after stop listening ,i will get this error : the same port can only be used once,
but i 've stop the Tcplistener after I enter the "Stop Listening" button,
i don't know why
who can help me
thanks


Re: .NET Framework Networking and Communication How to dispose TcpListener's holding port?

julien talois

normally your TCP listener component must have a "bind" propertie.

Search on this side or post your code...

Hope it helps.

JuuL





Re: .NET Framework Networking and Communication How to dispose TcpListener's holding port?

Amit Paka - MSFT

Are you indeed calling Stop on the Httplistener then the 'Stop Listening' button is pressed
Are you instantiating Httplistener with a specific IP address and port
Please post the code snippet.






Re: .NET Framework Networking and Communication How to dispose TcpListener's holding port?

RizwanSharp

It should work fine. Make sure you are using Start and Stop methods of TcpListener to start and stop respectively.

Best Regards,

Rizwan aka RizwanSharp






Re: .NET Framework Networking and Communication How to dispose TcpListener's holding port?

Indian Ocean

Hi,

Stop Listening button event handler code must have the line similar to the following,

objTcpListener.Stop() - this will stop the listener and close the underlaying socket.

If you still get the error, please post that code snippet where you find this problem,

HTH,






Re: .NET Framework Networking and Communication How to dispose TcpListener's holding port?

Alan J. McFarlane

Two other point should be raised:

1. Are you closing any accepted connections too If the TcpListener has returned N connections via AcceptSocket/AcceptTcpClient, then all the N connections must be closed too.

2. TCP (the protocol) mandates that a port cannot be reused with two minutes (etc) of the last connection using that port closing. So don't expect to be able to restart the listener within that period.

In a command prompt use "netstat -a" and look for instances using your server port; still connected connections will be ESTABLISHED, and those in the second situation will be in TIME_WAIT.