Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Port out of range error  RSS feed

 
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?
 
author and iconoclast
Posts: 24203
40
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!