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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:22:01+00:00 2026-05-31T01:22:01+00:00

i make a simple TCP client/server in C# and i have the problem. When

  • 0

i make a simple TCP client/server in C# and i have the problem. When i test my code with telnet, the server is reading the socket fine and wrote the result. But when my client is writting a sentence on the socket, the server is block at the readLine function.

Here you have my client :

 public Boolean initConnection(String ip)
        {
            try
            {
              this.client.Connect("127.0.0.1", 40000);
              this.output = this.client.GetStream();
              this.reader = new StreamReader(this.output, Encoding.UTF8);
              this.writer = new StreamWriter(this.output, Encoding.UTF8);
              writer.Write("one sentence");
              return (true);
            }
          catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return (false);
            }
        }

and here you have my server :

class SNetwork
    {
        private Thread Tread;
        private TcpListener server;
        private TcpClient client;
        private StreamReader reader;
        private StreamWriter writer;
        private NetworkStream output;
        private State state;

        public void initReading()
        {
            this.server = new TcpListener(IPAddress.Any, 40000);
            output = client.GetStream();
            reader = new StreamReader(output, Encoding.UTF8);
            writer = new StreamWriter(output, Encoding.UTF8);
            this.Tread = new Thread(new ThreadStart(this.read)); // this.Tread is a thread
            this.Tread.Start();
        }

   private void read()
        {
            try
            {
                while (Thread.CurrentThread.IsAlive)
                {
                    String result;

                    if (this.client.Client.Poll(10, SelectMode.SelectRead))
                    {
                        this.state = State.Closed;
                        break;
                    }
                    else
                    {
                        result = reader.ReadLine();
                        if (result != null && result.Length > 0)
                            Console.WriteLine(result);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
}

Anyone can help me plz ? i don’t find a solution

  • 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-31T01:22:02+00:00Added an answer on May 31, 2026 at 1:22 am

    This code:

    writer.Write("one sentence");
    

    isn’t writing a line terminator – so your server code doesn’t know that you’ve finished the line. Change it to WriteLine (and flush the writer) it should be okay.

    You always need to bear in mind that TCP/IP is a stream-based protocol – you can’t expect the server to receive the data with as many Read calls as you issued Write calls, and if you’re going for a line-terminated protocol on top, you need to make sure you terminate your lines.

    (As a separate matter, it would be a good idea to follow .NET naming conventions…)

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

Sidebar

Related Questions

Right now I've got a simple TCP server/client. I have it set up so
Ok, simple problem hopefully. I have started to make a simple server for a
I'm trying to build a simple multithreaded tcp server. The client connects and sends
I am writing a simple C# tcp client and server program. The server will
I'm trying to make a simple TCP server using Twisted ,which can do some
What am I missing? I have very simple client and server. The server uses
My goal is to make a simple TCP proxy application for my test lab.
I have some simple questions, I have a client-server application and data sent on
I'm implementing a simple TCP client and TCP server in Java at the moment,
I'm having issues getting a simple server/client socket app working in C# between two

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.