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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:17:49+00:00 2026-06-01T03:17:49+00:00

Through a lot of learning and research, i wrote a server side program. But

  • 0

Through a lot of learning and research, i wrote a server side program. But the problem with this program is that it doesn’t accept multiple clients, and i also wanted to know how to send the output back to client side instead of displaying it on the server side. Can someone please help me out with the code? This is what I’ve tried till now –

class Program
{

    private static Regex _regex = new Regex("not|http|console|application", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);


    static void Main(string[] args)
    {
        {

            TcpListener serversocket = new TcpListener(8888);
            TcpClient clientsocket = default(TcpClient);
            serversocket.Start();

            Console.WriteLine(">> Server Started");
            clientsocket = serversocket.AcceptTcpClient();
            Console.WriteLine("Accept Connection From Client");

            try
            {
                using (var reader = new StreamReader(clientsocket.GetStream()))
                {
                    string line;
                    int lineNumber = 0;
                    while (null != (line = reader.ReadLine()))
                    {
                        lineNumber += 1;
                        foreach (Match match in _regex.Matches(line))
                        {

                            Console.WriteLine("Line {0} matches {1}", lineNumber, match.Value);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.ToString());
            }
            clientsocket.Close();
            serversocket.Stop();
            Console.WriteLine(" >> exit");
            Console.ReadLine();
        }
    }
    }
  • 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-01T03:17:51+00:00Added an answer on June 1, 2026 at 3:17 am

    You could change it to something like this.

    static void Main(string[] args)
    {
       TcpListener serversocket = new TcpListener(8888);
       TcpClient clientsocket = default(TcpClient);
       serversocket.Start();
    
       Console.WriteLine(">> Server Started");
       while(true)
       {
          clientsocket = serversocket.AcceptTcpClient();
          Console.WriteLine("Accept Connection From Client");
          LineMatcher lm = new LineMatcher(clientsocket);
          Thread thread = new Thread(new ThreadStart(lm.Run));
          thread.Start();
          Console.WriteLine("Client connected");
       }
    
       serversocket.Stop();
       Console.WriteLine(" >> exit");
       Console.ReadLine();
    }
    

    And then have this seperate class handling the linematching

    public class LineMatcher{
        private static Regex _regex = new Regex("not|http|console|application", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
    
        private TcpClient _client;
    
        public LineMatcher(TcpClient client)
        {
            _client = client;
        }
    
        public void Run()
        {
            try
            {
                using (var reader = new StreamReader(_client.GetStream()))
                {
                    string line;
                    int lineNumber = 0;
                    while (null != (line = reader.ReadLine()))
                    {
                        lineNumber += 1;
                        foreach (Match match in _regex.Matches(line))
                        {
    
                            Console.WriteLine("Line {0} matches {1}", lineNumber, match.Value);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.ToString());
            }
            Console.WriteLine("Closing client");
            _client.Close();
        }
    }
    

    This is purely a proof of concept and is no way stable code 😉
    Please note that this doesn’t manage the child-threads in any way.
    There is also no correct way of shutting down the listener because of the while(true)

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

Sidebar

Related Questions

Looking through my server logs, I see that a lot of pages on my
I've done a lot of reading through forum posts and tutorials, but I still
I'm going through the exercise of building a CMS that will organize a lot
This is going to sound like a silly question, but I'm still learning C,
I am learning to program in Delphi Prism and have gone through a crash
So I've got this server application running on Google AppEngine that I want to
I'm going through a lot of files and on each file I need to
I've been reading through a lot of the rookie Java questions on finalize() and
I'm getting started with Astoria/ADO.NET Data Services/WCF Data Services. Looking through a lot of
I'm going through MSIL and noticing there are a lot of nop instructions in

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.