Click here to Skip to main content
11,802,442 members (70,944 online)
Rate this: bad
Please Sign up or sign in to vote.
I'm working on a simple java server to accept a port number and display internet data such as text, images, and directories and am having some trouble getting some code to work. this is my class

public class HTTPServer {
    public static void main(String[] args) {
        ServerSocket socket = null;
            socket = new ServerSocket(5000);
        catch (Exception ex0) 
            System.exit(1); // exit with error.
This first part works fine but when I try to accept a connection the program stalls. The line "Waiting For Client Connection" is output to screen and then nothing happens

            // the server waits (using an accept call) for a client to connect.
            System.out.println("Waiting For Client Connection.");
            Socket connection = null;
                connection = socket.accept();
            catch (Exception ex1) 
                System.exit(1); // exit with error.
            System.out.println("Client Connected To Server");

The next line "Client Connected To Server" is never output to the screen and exception ex1 is never triggered. I'm very confused about this. Does anyone have any suggestions?
Posted 26-Apr-12 21:15pm
Richard MacCutchan at 27-Apr-12 4:56am
What happens at the client end?
ryanplawrence at 27-Apr-12 10:24am
i dont know. i am only required to implement server side for my project

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 465
1 KrunalRohit 366
2 F-ES Sitecore 295
3 Sergey Alexandrovich Kryukov 241
4 Afzaal Ahmad Zeeshan 230
0 OriginalGriff 2,950
1 Maciej Los 1,910
2 KrunalRohit 1,862
3 CPallini 1,645
4 Richard MacCutchan 1,157

Advertise | Privacy | Mobile
Web01 | 2.8.151002.1 | Last Updated 27 Apr 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100