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

The Archive Base Latest Questions

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

Basically I’ve written this program to check for strings. I’ve used socket method for

  • 0

Basically I’ve written this program to check for strings. I’ve used socket method for this.

The problem is, I am unable to figure out how and where exactly to open the file in this program and search for the strings. Instead of giving the search string in the program, I want the client to be able to type/search for any strings they want. And when I run the program, I need the output on client’s screen.

How can I improve this program? Could someone please help me out with the code?

This is my program :

class Program
{
    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");
        }
        Console.WriteLine(" >> exit");
        Console.ReadLine();
        clientsocket.Close();
        serversocket.Stop();
    }
}
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();
    }
} 
  • 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:24:14+00:00Added an answer on June 1, 2026 at 3:24 am

    Here is a simple demo client that works for me:

    using System;
    using System.IO;
    using System.Net.Sockets;
    using System.Text;
    
    namespace AClient
    {
        class Client
        {
            static void Main()
            {
                using (var client = new TcpClient("localhost", 8888))
                {
                    Console.WriteLine(">> Client Started");
    
                    using (var r = new StreamReader(@"E:\input.txt", Encoding.UTF8))
                    using (var w = new StreamWriter(client.GetStream(), Encoding.UTF8))
                    {
                        string line;
                        while (null != (line = r.ReadLine()))
                        {
                            w.WriteLine(line);
                            w.Flush(); // probably not necessary, but I'm too lazy to find the docs
                        }
                    }
    
                    Console.WriteLine(">> Goodbye");
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, I've seen this used all to often: public event MyEventHandler MyEvent; private void
Basically what I want to do it this: a pdb file contains a location
Basically, something better than this: <input type=file name=myfile size=50> First of all, the browse
Basically I have some code to check a specific directory to see if an
Basically from a database I am getting data that is formatted like this nameofproject101
Basically I'm attempting to add rows to a table, I need to do this
Basically this function is meant to store the height value of the element that
Basically I have a loop incrementing i, and I want to do this: var
Basically, I'm using python to print out some information in the terminal and some
Basically I have this server app I built in vc#, and for some reason

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.