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 3975318
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:40:15+00:00 2026-05-20T04:40:15+00:00

I had recently asked a related question In C# how do I have a

  • 0

I had recently asked a related question In C# how do I have a socket continue to stay open and accept new data? and somewhat solved it, but now I’m having trouble getting my server to receive data from the same client more than once.

I have written a simple socket server using a windows form in VS that has a button that calls a receive function

public void Receive()
    {
        try
        {
            byte[] bytes = new byte[256];
            received = s1.Accept().Receive(bytes);
            receivedText.Text += System.Text.ASCIIEncoding.ASCII.GetString(bytes);
        }
        catch (SocketException e)
        {
            Console.WriteLine("{0} Error code: {1}.", e.Message, e.ErrorCode);
            return;
        }
    }

It works if the first time I send from my client, but if I try sending anything else and click on receive, my server just loops and never picks up the new data. However, if I send from somewhere else, or restart the connection from my client, I’m able to send data.

I would like to have my server able to receive any amount of data from the same client(s) at a time. Please ask if you need more code/details. Not sure what’s relevant as I’m pretty new to socket programming.

  • 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-20T04:40:16+00:00Added an answer on May 20, 2026 at 4:40 am

    You must call Accept() only once per client, not every time you want to receive new data. Accept() basically waits for a client to connect to your server socket, s1 (and returns a new socket to send/receive data with this client), so here each time your Receive() function is called your socket waits for another client to connect, that’s why it works only once.

    Here is an example (the code comes from your previous question) :

    s1.Bind(endP);
    s1.Listen(10);
    Socket s2 = s1.Accept(); // Waits for a client to connect and return a socket, s2, to communicate with him
    while (true) {
        Receive(s2);
    }
    ...
    

    Receive() function :

    public void Receive(Socket s)
    {
        try
        {
            byte[] bytes = new byte[256];
            received = s.Receive(bytes);
            receivedText.Text += System.Text.ASCIIEncoding.ASCII.GetString(bytes);
        }
        catch (SocketException e)
        {
            Console.WriteLine("{0} Error code: {1}.", e.Message, e.ErrorCode);
            return;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently asked a question (and had it answered) here: jQuery Load JSON I
I've recently asked and had answered this question and it's stopped the issue of
This is closely related to another question I asked: Is there functionality that is
Quite recently, I asked a question about debugging a seg fault: What are some
I recently asked a colleague why they had included _TABLE at the end of
I recenty asked a question about parallel programming algorithms which was closed quite fast
I recently asked about functional programs having no side effects, and learned what this
I was recently asked by a friend of mine who's just starting to play
I was recently asked in an interview about the parameter for a copy constructor.
I was recently asked to update an old Access Forms application. Coming from a

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.