Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9006931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:32:40+00:00 2026-06-16T01:32:40+00:00

I created a multithreaded client-server chat application and want to test my application with

  • 0

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).

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.

This is my connection establishing part

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 );
        }
    }

and my data sending part

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 );
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:32:44+00:00Added an answer on June 16, 2026 at 1:32 am

    If you really need to set the client socket address before making a connection to the server, and it is often a valid scenario when one wants to force the kernel to bind to a specific local address on multihomed systems, you may call Socket.Bind() before you call Socket.Connect():

    IPAddress  localIPAddress = IPAddress.Parse(szLocalIP);
    IPEndPoint localEndPoint  = new IPEndPoint(localIPAddress, 0);
    m_socWorker.Bind(localEndPoint);
    
    m_socWorker.Connect(remoteEndPoint);
    

    You may also explicitly specify the local port number in the IPEndPoint constructor, but you have to make sure, that the port is not in use. If you leave the port number equal to 0, then the system would pick an (almost) arbitrary free port number.

    Note that you cannot just pick an arbitrary client IP address – it must be one of the addresses, configured on your system’s enabled network interfaces. See the output of ipconfig /all for what is configured. You can assign more than one IP address to an interface if you simply want to test.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a multithreaded application but it still hangs if the server is
I created cookie with server side code (c#) and it was shown in chrome
I am writing a multithreaded client that uses an IO Completion Port. I create
I have an email account on a remote server. I created an application that
I am programming a multi-threaded chat server application. Thus critical section are very necessary.
My java application has to send messages(multithreaded) to a socket server. The application can
I am developing a simple web application which contains these 3 components: client that
can i directly create unit of work on server session instead of creating multiple
The server is intended to be a multithreaded server which spawns new threads upon
We have created a multi-threaded application which process/parse big files (few hundred MB's) simultaneously.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.