title: How to set IP address of client manually in .net socket program
body: <p>I created a multithreaded client-server chat application and want to test my application with multiple clients. I'm planning to create a simulator in client side which create a random port and IP. By that I mean my client system should run with multiple ports (without running multiple times).</p>
  
  <p>I tried to find out the part of the code which gives client IP and port number in the client class, but couldn't figure it out. I only found the part which gives server IP and port.</p>
  
  <p>This is my connection establishing part</p>
  
  <pre><code>private void cmdConnect_Click(object sender, System.EventArgs e)
      {
          try
          {
              //create a new client socket ...
              m_socWorker = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
              String szIPSelected  = txtIPAddress.Text;
              String szPort = txtPort.Text;
              int  alPort = System.Convert.ToInt16 (szPort,10);
  
  
              System.Net.IPAddress    remoteIPAddress  = System.Net.IPAddress.Parse(szIPSelected);
              System.Net.IPEndPoint   remoteEndPoint = new System.Net.IPEndPoint(remoteIPAddress, alPort);
              m_socWorker.Connect(remoteEndPoint);
          }
          catch (System.Net.Sockets.SocketException se)
          {
              MessageBox.Show ( se.Message );
          }
      }
  </code></pre>
  
  <p>and my data sending part</p>
  
  <pre><code>private void cmdSendData_Click(object sender, System.EventArgs e)
      {
          try
          {
              Object objData = txtData.Text;
              byte[] byData = System.Text.Encoding.ASCII.GetBytes(objData.ToString ());
              m_socWorker.Send (byData);
          }
          catch(System.Net.Sockets.SocketException se)
          {
              MessageBox.Show (se.Message );
          }
      }
  </code></pre>