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:
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.