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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:59:54+00:00 2026-05-29T17:59:54+00:00

Few hours ago I have started to learn java socket comunication. Now I’m trying

  • 0

Few hours ago I have started to learn java socket comunication. Now I’m trying to make server application whitch should return me data to webbrowser.
My code:

try{
    ServerSocket socket = new ServerSocket(80);
    Socket response = socket.accept();
    String lol = "<html>hi</html>";
    OutputStream str = response.getOutputStream();
    str.write(lol.getBytes("US-ASCII"));
    str.flush();
    response.close();
    System.out.println("LOL works!");
    }catch(IOException ex)
    {
        System.out.println(ex.toString());
    }
}

I have no error in server application, the message “LOL works!!!” prints in console but in webbrowser I’m getting this error:

My error.

Does anobody know how to repair it and get the text “hi” in webbrowser? Thanks.

EDIT:
I’ve tried add it to telnet. This is the result:
Telnet result

  • 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-29T17:59:54+00:00Added an answer on May 29, 2026 at 5:59 pm

    You cannot just send out raw data to the browser and expect it to handle it – you have to follow the HTTP (protocol) which is described in RFC1945.

    Specifically, you have to send out a few headers followed by a new line first as described in Section 4.1 of RFC1945.

    try{
        ServerSocket socket = new ServerSocket(80);
        Socket response = socket.accept();
        String lol = "<html>hi</html>";
        writer = new PrintStream(response.getOutputStream());
        writer.println("HTTP/1.1 200 OK");
        writer.println("Content-Type: text/html");
        writer.println();
        writer.println(lol);
        writer.flush();
        response.close();
        System.out.println("LOL works!");
        }catch(IOException e)
        {
            e.printStackTrace();
        }
    }
    

    Note that I’ve also wrapped your OutputStream in a PrintStream, since this is a lot easier than handling the OutputStream manually.

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

Sidebar

Related Questions

Hello only have a few hours with Java. (from Python) I am trying to
Based on this SO question asked a few hours ago, I have decided to
I started using WordPress just a few hours ago because I need to develop
A few weeks ago I started my first project with TDD. Up to now,
I started to use php a few hours ago. To begin studying I decided
i have posted a few hours ago question about newtons method,i got answers and
I have been working on an inherited webapp project and a few hours ago
A few hours ago, I was instructed how to style a specific textarea with
For a few hours I was figuring out how to make an inner join
I've been for the past few hours trying to figure out why openCV doesn't

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.