Skip to content

Socket client - server: issue: port in use on client side

Arne Solhaug

Asked Apr 9, 2006, 11:24 AM EDT1 answer
Share
LinkedInX

C# socket application :

Ther server is runing on a dedicated port and client obtain connection to it along with the server IP adr. When I'm writing out information about the connection on serverside, i can see the client IP adress as well as the port used at client.  I have not spesified any dedicated port
to use on client side, guess it just pick a port not in use from the free range IP ports.

Using Async socket comunication, data transpher both ways.

The question: How can I controll the port in use on clientside when establish the connection against server ?


The underlying worry is when the application is to bee deployed in a seting where firewall has to bee configured on trafic in both direction - ther serverside wher port is set is no problem,
but I have so far not been able to take kontrol on client side port to bee used in the socket session

Tanks to contribution!

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • +1

    I have got it supported in constructor of TcpClient:
    On TcpClient, spesify local endpoint before obtaining the connection to server
    snippet:
    ...
    //local endpoint
    IPAddress ipAddress = Dns.Resolve (Dns.GetHostName ()).AddressList[0];IPEndPoint ipLocalEndPoint = new IPEndPoint (ipAddress, port); //
    _socket = new TcpClient(ipLocalEndPoint);
    //do connect server
    _socket.Connect(ServerAdr,4990);
    ...

    +1