tags:

views:

302

answers:

1

Hi.

i am developing a small TCP Client/Server lib.

i am facing this problem when i create a client and connect it to server. it gives me this exception

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

my code is.

 public TCPClient(string remoteIPAddress, int port)
        {
            this.remoteIPAddress = IPAddress.Parse(remoteIPAddress);
            this.port = port;

            IPEndPoint remoteEndPoint = new IPEndPoint(this.remoteIPAddress, this.port);
            tcpClient = new TcpClient(remoteEndPoint);
        }

and here is TCPServer

 public TCPServer(int listeningPort)
        {
            this.listeningPort = listeningPort;            

            tcpListenter = new TcpListener(this.listeningPort);
            workers = new List<TCPServerWorker>();
            this.keepRunning = false;
        }

any help that why i am getting this exception

+1  A: 

solved.

i used

 tcpClient = new TcpClient();
            tcpClient.Connect(remoteIPAddress, port);
Mohsan