Results 1 to 2 of 2
  1. #1
    providence is offline Member
    Join Date
    Oct 2010
    Location
    Canada
    Posts
    20
    Rep Power
    0

    Default Having trouble with ServerSocket

    I am trying to do the tutorial at oracle.com for sockets. I have written the sample server program and I am trying to test it out. I am getting this error:

    Could not listen on port: 1313
    Exception in thread "main" java.lang.NullPointerException
    at com.newera.backbone.OpenEars.main(OpenEars.java:25 )

    from this part of code:
    Java Code:
    try {
    		serverSocket = new ServerSocket(1313);
    	} catch (IOException e) {
    		System.out.println("Could not listen on port: 1313");
    	}
    	
    	Socket clientSocket = null;
    	
    	try {
    		clientSocket = serverSocket.accept();
    	} catch (IOException e) {
    		System.out.println("Failed to Accept Connection");
    		System.exit(-1);
    	}
    I have tried a bunch of different ports, so I'm confident that the port is not already occupied. I am testing this on my desktop computer and not a dedicated server (not finished setting it up), could this possibly be the cause? I don't think it should be, as all I am trying to do is listen to a port. Then again, I don't really know all that much about ports and sockets, so... Any help will be appreciated.
    Last edited by providence; 01-29-2011 at 03:44 AM.

  2. #2
    providence is offline Member
    Join Date
    Oct 2010
    Location
    Canada
    Posts
    20
    Rep Power
    0

    Default

    Ok, never mind. In case anyone else ever has this problem, make sure that a previous run of the program isn't already listening on the port in question. Stupid mistake on my part..

Similar Threads

  1. Write all possible ways to create ServerSocket.
    By anuj08mishra in forum New To Java
    Replies: 1
    Last Post: 12-01-2010, 11:34 PM
  2. HTTP ServerSocket
    By Dennis in forum Advanced Java
    Replies: 0
    Last Post: 12-01-2010, 03:27 PM
  3. ServerSocket.accept() using 100%+ CPU
    By pagod in forum Networking
    Replies: 2
    Last Post: 05-28-2010, 10:42 AM
  4. serversocket listen connection
    By gisler in forum Networking
    Replies: 1
    Last Post: 12-17-2009, 03:57 AM
  5. problem with ServerSocket on Linux
    By gabriel in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 05:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •