• Post Reply Bookmark Topic Watch Topic
  • New Topic

Port out of range error

 
Simon Knight
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I'm trying to develop a client server app for uni, but I keep getting a port out of range error. Here's the server code:



And here's the client:



With SOCKETNUM = 1975 again. First I run the server, then the client but I always get a port out of range error. Can anyone explain why?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Simon Knight:
I always get a port out of range error. Can anyone explain why?


Well, because SOCKETNUM is not 1975. Maybe something needs to be recompiled, or there's a typo somewhere. You could use a debugger, or just insert a print statement to show what SOCKETNUM is at that point.

But in general if you get an error message that says X, and you believe something that conflicts with X, then it saves a lot of time to just change your mind and believe X!
 
Simon Knight
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, because SOCKETNUM is not 1975. Maybe something needs to be recompiled, or there's a typo somewhere. You could use a debugger, or just insert a print statement to show what SOCKETNUM is at that point.


Um - thanks for your input, but inserting



results in 1975, then the same error. Some less patronising assistance would be helpful.
 
Simon Knight
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For some reason - calling the getSocket() method (below) directly from main, though still in a try catch block, works fine.



But if it is called from within another method, like this:



I get the port out of range error already detailed above. Can anyone explain what's going on here? I've already checked the value(s) of PORTNUM in my code, and the value can be further verified by calling toString() on the Socket object within getSocket - System.out.println(server), resulting in:

Socket[addr=simon/192.168.1.162, port=1975, localport3942].

Any ideas?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!