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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:42:45+00:00 2026-05-20T09:42:45+00:00

(C#) Here I created a socket listener application which waits for the client hit.

  • 0

(C#) Here I created a socket listener application which waits for the client hit. Now my requirement is my application should listen up to 30 seconds only later it should throw an error saying “Request Timed Out”. Any suggestions ?

        try
        {
            Byte[] bytes = new Byte[256];
            String data = null;
            // Enter the listening loop.
            while (true)
            {
                ReceiveTimer.Stop(); ;
                logger.Log("Waiting for a connection... ");

                // Perform a blocking call to accept requests.
                // You could also use server.AcceptSocket() here.
                TcpClient client = server.AcceptTcpClient();


                logger.Log("Connected!");

                data = null;

                // Get a stream object for reading and writing
                NetworkStream stream = client.GetStream();

                int i;

                // Loop to receive all the data sent by the client.
                while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
                {
                    // Translate data bytes to a ASCII string.
                    data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
                    logger.Log("Received: {0}", data);

                    // Process the data sent by the client.
                    data = data.ToUpper();

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

                    // Send back a response.
                    stream.Write(msg, 0, msg.Length);
                    logger.Log("Sent: {0}", data);
                }

                // Shutdown and end connection
                client.Close();
                logger.Log("Shutdown and end connection");
            }
        }
        catch (SocketException ex)
        {
            logger.Log("SocketException: " + ex);
        }
  • 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-20T09:42:46+00:00Added an answer on May 20, 2026 at 9:42 am

    Why would you want to limit the time that the server listening ?

    Server should be listening all the time that it’s running.

    Anyway, You can create a task(thread) that will be listening and after the timeout will be canceled.

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

Sidebar

Related Questions

I have created my web socket server and client using this simple tutorial here
Has anyone here created a Flash site or application that is ADA (Section 508)
I created a coffeescript version from the second example here: http://socket.io/#how-to-use In the example
I am trying to connect to unix domain socket created by another process. here
I have created small socket programs (client/server). Client will transfer all formats of files
I am trying to emulate another form that the other developer here created. In
I know that many threads has been created here & on the internet about
I am trying to add an attirubute to objects that i created.Here i created
Here is the deal: I created an SVN repository, say, foo. It is at
Here's our scenario: We've created a sharepoint 2007 calendar on our intranet site We

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.