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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:10:18+00:00 2026-06-02T19:10:18+00:00

I need to implement a very basic web server for homework. The way I

  • 0

I need to implement a very basic web server for homework. The way I do it is as follows:

        TcpListener server = new TcpListener(IPAddress.Any, 8181);
        server.Start();

        // when a client connects this is what we will send back
        var HttpHeader = 
              "HTTP/1.1 200 OK\r\n"
            + "Content-Type: text/html\r\n"
            + "Content-Length: [LENGTH]\r\n\r\n";

        var html = "<h1>Hello Wold</h1>";

        // replace [LENGTH]  with the length of html
        HttpHeader = HttpHeader.Replace("[LENGTH]", html.Length.ToString());

        while (true)
        {
            // wait for client to connect
            var client = server.AcceptTcpClient();

            using (var stream = client.GetStream())
            {
                var messageToSend = HttpHeader + html;
                var sendData = System.Text.Encoding.ASCII.GetBytes(messageToSend);
                stream.Write(sendData, 0, sendData.Length);

                Thread.Sleep(2000);                    
            }                
        }

Here is what happens when I run the program:

enter image description here

So as you can see the first loop works great. The problem comes when I loop again hoping to connect other clients not the same one.


Edit

enter image description here

  • 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-02T19:10:21+00:00Added an answer on June 2, 2026 at 7:10 pm

    It sounds like your problem starts with using a browser and assuming it’ll issue exactly one request. It doesn’t – it’ll do additional things like try to request FavIcon. Use WGET or write a test client using HttpWebRequest it’ll give you consistent reliable results. If that doesn’t give the result you want – then come back.

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

Sidebar

Related Questions

I need to implement a very simple web-server-like app in Python which would perform
I need some suggestions for how to implement a very basic mechanism that logs
I'm a fairly new programmer and very new to web programming and I need
I need to implement a very specific demo mechanism. It must not expire after
I need to implement a server that can send Push Notifications to Android mobile
I'm trying to implement a very basic eigenface calculation in Matlab. It kind of
I'm looking to implement a very basic shopping cart. Satchmo seems to install a
I need to implement a tree of decisions, very simple, not complicated in objective
I'm working on an iOS app in which I need to implement a basic
I am currently trying to implement basic speech recognition in AS3. I need this

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.