Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Web server in java

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Thanked 0 Times in 0 Posts

    Post Web server in java

    a program that opens a server socket on the http port, port 80, and listens for requests from web browsers. You echo the requests, but don’t act on them.It has to be split in two classes.It is not showing any result.just displaying
    have opened port 80 locally
    what is wrong on my code?

    final int httpd = 80;
        ServerSocket ssock = new ServerSocket(httpd);
        System.out.println("have opened port 80 locally" );
    	Socket sock = ssock.accept();
        System.out.println("client has made socket connection");
        OneConnection client = new OneConnection(sock);
        String s = client.getRequest();
    	catch (IOException e) {
    OneConnection(Socket sock) throws IOException{
        this.sock = sock;
         in = new BufferedReader(new InputStreamReader( sock.getInputStream() ) );
         out = new DataOutputStream(sock.getOutputStream());
      String getRequest() throws IOException {
       String s=null;
        while ( (s=in.readLine())!= null) {
           System.out.println("got: "+ s);
        return s;

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Eastern Florida
    Thanked 2,475 Times in 2,426 Posts

    Default Re: Web server in java

    What program are you using to connect to your server? What URL are you using?

    The call to close() will close the connection before any communications take place.

    The catch() block should have a call to the printStackTrace() method so you get the full text of any error messages.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 0
    Last Post: July 24th, 2013, 07:17 AM
  2. Replies: 5
    Last Post: March 2nd, 2012, 11:34 AM
  3. [SOLVED] Uploading a Java Applet embedded in HTML to a Web server
    By wizdom in forum What's Wrong With My Code?
    Replies: 20
    Last Post: December 3rd, 2011, 10:13 AM
  4. Java web client - > .NET web service
    By codeJ in forum Web Frameworks
    Replies: 0
    Last Post: July 8th, 2010, 04:34 AM
  5. Replies: 2
    Last Post: July 7th, 2009, 02:34 PM