• Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating IP for server

 
henk eetvis
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working on a server, but that server needs his own IP address and not my local IP or my external IP
Is there a way to do this in java?

Because this is not working:

 
Stephan van Hulst
Bartender
Posts: 6583
84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch, Henk!

Is there a reason you're specifying an IP address at all? If you create a ServerSocket without one, you can just access it from another host using any of the server's local IP addresses.
 
henk eetvis
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I have to use another IP because I cannot run mutliple servers with the same port (80) and that port is required for what im doing
 
Stephan van Hulst
Bartender
Posts: 6583
84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you should create a socket for each of the host's assigned addresses. InetAddress has a getAllByName() that you can use to get all the assigned IP addresses.
 
henk eetvis
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't really get that solution.
How can I fix it with that method? the ServerSocket doesn't accept InetAddress[] and if I use for example InetAddress[0] it still fails.
 
Stephan van Hulst
Bartender
Posts: 6583
84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well there's not much we can do with "it fails".

Please post the error you're getting.
 
henk eetvis
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.net.BindException: Cannot assign requested address: JVM_Bind
at java.net.DualStackPlainSocketImpl.bind0(Native Method)
at java.net.DualStackPlainSocketImpl.socketBind(DualStackPlainSocketImpl.java:106)
at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:387)
at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:190)
at java.net.ServerSocket.bind(ServerSocket.java:375)
at java.net.ServerSocket.<init>(ServerSocket.java:237)
at does.it.work.LetsCheckIt.main(LetsCheckIt.java:15)

What im trying to get is:

my local machine has the ip (for example): 192.168.178.44
I want to give the java application (server) the ip (for example): 192.168.178.77
 
Stephan van Hulst
Bartender
Posts: 6583
84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Uhuh, and could you maybe print the result of running the following statements on the server:

 
henk eetvis
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That gives me:

PCNAME/192.168.178.99
PCNAME/fe80:0:0:0:41ea:2943:bcaf:9966%9
 
Tim Holloway
Bartender
Posts: 18416
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't create an IP address, you are assigned an IP address.

Either a network administrator gives you an IP address to configure for your server, or a DHCP server assigns one to you.

Furthermore, a server may have multiple IP addresses. My production servers all have 2 or 3 NICs in them, each of which as at least one (and sometimes many more) IP addresses assigned.

The port number limitation, however, isn't based on IP address. It's based on the entire OS instance. If my server has internal IP 10.0.1.22 and external IP 216.199.14.31, port 80 can only belong to one server app on the machine, even if only one of those network addresses is permitted to listen on port 80.

The only way you can have the same port number for different servers on the same box is if the box is a virtual host and each VM (or container) has its own set of ports, courtesy of the network virtualization subsystem.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!