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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:55:30+00:00 2026-06-08T02:55:30+00:00

I have this code. I can receive data from my client successfully, but only

  • 0

I have this code. I can receive data from my client successfully, but only one time. After I receive the data once, if the client attempts to send any more the server isn’t receiving it. Can anyone help?

    private void startListening()
    {
        TcpListener server = null;


        try
        {

            server = new TcpListener(IPAddress.Parse("127.0.0.1"), 7079);

            server.Start();

            Byte[] bytes = new Byte[256];
            String data = null;

            //Enter listening loop
            while (true)
            {

                addLog("Waiting for push.");

                TcpClient client = server.AcceptTcpClient();
                addLog("Push request received, accepted.");

                data = null;

                NetworkStream stream = client.GetStream();

                int i;

                //Loop to receive all data
                while((i = stream.Read(bytes, 0, bytes.Length))!=0)
                {
                    //Translate data bytes to ASCII string
                    data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);

                    //Process data
                    data = data.ToUpper();

                    byte[] msg = System.Text.Encoding.ASCII.GetBytes(data);

                    //send response
                    stream.Write(msg, 0, msg.Length);
                    addLog("Received: '" + data + "'");
                }

                //End ALL Connections
                client.Close();
                server.Stop();
            }
        }
        catch(SocketException e)
        {
            addLog("SocketException: " + e);
        }
        finally
        {
            //Stop listening for new clients
            MessageBox.Show("Finished.");
        }
    }
  • 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-08T02:55:31+00:00Added an answer on June 8, 2026 at 2:55 am

    You are closing both the server and the client in the end of your loop (server.Stop();). Your outer loop will keep going and try to get a new TcpClient from your server (which would mean a new connection is made) but since you’ve already stopped the server then that will never happen (or probably throw an exception).

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

Sidebar

Related Questions

I have this code to update users data, but I can't write the for
I have written the code for sending/receiving data from a client socket. The sending
I have this code which can display drop down in div tag of html.
I have this code ,now can anyone reply s what happens to the lock
I have this code and can't figure out what seems to be the problem:
I have this code so I can grab the values ind the dataset before
i have this code in c# doc.SelectSingleNode(WhoisRecord/registrant/email).InnerText how can i check whether it is
I have this code below. As you can see I am passing two variables
I have this code in Linq. Anybody can provide the t-sql. thanks! var tsr
Challenge: I have this code that fails to compile. Can you figure out what's

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.