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

  • Home
  • SEARCH
  • 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 6612737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:08:02+00:00 2026-05-25T20:08:02+00:00

im new to C# and any help/feedback would be appreciated. im trying to develop

  • 0

im new to C# and any help/feedback would be appreciated. im trying to develop a a client-server program in c#, however i do have different clients sending information to the server side. Is there any function similar to the c language select() such that can help to get all the information from every client side in C#?

here is my server side code:

// Create the listening socket...
m_mainSocket = new Socket(AddressFamily.InterNetwork, 
                          SocketType.Stream, ProtocolType.Tcp);
IPEndPoint ipLocal = new IPEndPoint(IPAddress.Any, 9051);

// Bind to local IP Address...
m_mainSocket.Bind(ipLocal);

// Start listening...
m_mainSocket.Listen(10);
Socket clientSock = m_mainSocket.Accept();
byte[] clientData = new byte[1024];
int receivedBytesLen = clientSock.Receive(clientData);
string clientDataInString = 
           Encoding.ASCII.GetString(clientData, 0, receivedBytesLen);
string clientStr = "Client Data Received: " + clientDataInString;
byte[] sendData = new byte[1024];
sendData = Encoding.ASCII.GetBytes(clientStr);
clientSock.Send(sendData);
clientSock.Close();
  • 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-05-25T20:08:02+00:00Added an answer on May 25, 2026 at 8:08 pm

    You want to accept connections from more than one client, so you have to call the blocking Accept method again after acception a connection:

    while (true)
    {            
        var clientSocket = s.Accept();
        beginReceive(clientSocket);
    }
    

    After accepting you might want to start receiving data in an async manner:

    private static void beginReceive(Socket clientSocket)
    {
        byte[] buffer = new byte[1000];
        clientSocket.BeginReceive(
               buffer, 0, 1000, SocketFlags.None, OnReceiveData, clientSocket);
    }
    

    And finally here is the callback method which is called by the framework on another thread when data arrives. You have to finish the async call with EndReceive:

    private static void OnReceiveData(IAsyncResult ar)
    {
        int bytesReceived = ((Socket) ar.AsyncState).EndReceive(ar);
        // process data...
    }
    

    Of cause you have to store your buffer somewhere else and maintain one receive buffer per client. Maybe you should write an own class for managing a connected client.

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

Sidebar

Related Questions

I am new to jQuery. Any help would be appreciated I have two radio
I am relatively new to db design, so any help here would be appreciated.
I'm very new to this, so any help is appreciated. I'll use the Dinners/RSVPs
any help with this would be great. I have a model public class Master
I am new to C++. I am getting HEAP CORRUPTION ERROR. Any help will
I am new in Pocket PC and Smart phone. so can any one help
When I try to install/update any plugin from Help -> Install New Software I
im new to obj-c, and need help im trying to dynamically load data (10
I am very new to Java and also Real Time Program. I am trying
I have been trawling google for answers to this but no luck. Any help

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.