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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:16:51+00:00 2026-05-11T15:16:51+00:00

I’m using visual studio to program this small TcpServer. It’s really specific. The server

  • 0

I’m using visual studio to program this small TcpServer.

It’s really specific. The server listens to port 1234 and is located on IP 127.0.0.1 Our teachers gave us a program that tries to connect to that port on that IP when you click ‘connect’. It’s working for everyone else, so it must be a coding error on my part.

When I click connect, the program sends the word ‘GET’ over the stream, to which I have to respons with a list of allready connected IP-adress and then a newline containing only a .

When I disconnect, the program sends the word ‘REM’ and I simply have to remove if from my list(which is a generic list)

I have a class TCPServer(we had to make our own), which has this as main code:

this.tl = new TcpListener(IPAddress.Any, PORT); tl.Start(); while(true) {   TcpClient tcl = tl.AcceptTcpClient();//here the server will wait forever untill someone connects, meaning the 'new Thread' statement is never reached untill someone connects.   TcpHelper th = new TcpHelper(tcl,conf);   new Thread(new ThreadStart(th.Start)).Start();//should be multi-threaded, not sure if it is.   //t.Start(); } 

TcpHelper looks like this(look for the commented text ‘here’s the problem’ within the usings):

public class TcpHelper {     private TcpClient tc;     private IPEndPoint ipe;     private string get;     private Configuration conf;      public TcpHelper(TcpClient tc, Configuration conf)     {        this.tc = tc;        this.conf = conf;     }      public void Start()     {        using (NetworkStream nws = this.tc.GetStream())        {            using (StreamReader sr = new StreamReader(nws))            {               using (StreamWriter sw = new StreamWriter(nws))               {                   this.ipe = (IPEndPoint)tc.Client.RemoteEndPoint;                   this.conf.List.Add(this.ipe.Address);                   bool conn = true;                    while (conn)                   {                       this.get = sr.ReadLine();//here's the problem                       switch (this.get)                       {                           case 'GET':                               foreach (IPAddress address in this.conf.Lijst)                               {                                   sw.WriteLine(address.ToString());                               }                               sw.WriteLine('.');                               break;                            case 'REM':                               this.conf.List.Remove(this.ipe.Address);                               sw.WriteLine('OK.');                               conn = false;                               break;                            default:                               break;                      }                   }               }           }       }   }    #region Properties   public IPEndPoint Ipe   {       get       {           return this.ipe;       }   }   #endregion } 
  • 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. 2026-05-11T15:16:52+00:00Added an answer on May 11, 2026 at 3:16 pm

    Sorry, maybe I’m not understanding this… Did you write this code?

    this.tl = new TcpListener(IPAddress.Any, PORT); tl.Start(); while(true) {   TcpClient tcl = tl.AcceptTcpClient();   TcpHelper th = new TcpHelper(tcl,conf);   new Thread(new ThreadStart(th.Start)).Start();   //t.Start(); } 

    This is going to blow the **** out of any computer. You’re looping infinitely, creating new threads on each loop. So, if you create one new thread per loop, and each loop takes one millisecond (lets say its very slow!), in five seconds you’ve got 5,000 threads. Each trying to listen at the same port.

    Try using a single thread. If this is a console app, use Console.ReadLine() to block the main thread until somebody presses the enter key.


    With the new information… AcceptTcpClient blocks, but instead of creating a new thread the work should be queued on the ThreadPool.

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

Sidebar

Ask A Question

Stats

  • Questions 122k
  • Answers 122k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The access() POSIX function can check the permissions without opening… May 12, 2026 at 12:42 am
  • Editorial Team
    Editorial Team added an answer Looking at Kenny Kerr's AutoPtr, it transfers ownership in its… May 12, 2026 at 12:42 am
  • Editorial Team
    Editorial Team added an answer Check out Smaz: Smaz is a simple compression library suitable… May 12, 2026 at 12:42 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.