1

I have 14 java processes running on one blade. Each process have binding to virtual IP recognized by ProxyServer (F5), so when external client call to F5 his call redirected to one of 14 processes.

Most of all, my process (one of 14) perform call to another application running on different blade.

Here is the question: How can I control source IP in outgoing TCP packets on java process running with virtual IP on TCP client? In other words I am looking for a way to set virtual IP as the source address in outgoing TCP packets. (by default it set to physical IP of the blade).

Mike Pennington
  • 41,899
  • 19
  • 136
  • 174
  • 1
    I've answered below but I'm interested why you need to set up your server this way. It doesn't sound very efficient and 14 JVMs on one box will have a massive memory requirement. – Alastair McCormack Oct 20 '12 at 10:46
  • We are using 14 JVM for physical memory division to avoid garbage collector hard working and take significant CPU time. Each JVM using 1G memory, so each garbage collector should work with 1G only. – David Greenshtein Oct 20 '12 at 11:05
  • I understand the rationale but I think it's too granular. I would also use ports rather than IP addresses. Also, why do you want the client to bind to a particular port for outgoing/inter-JVM communication? – Alastair McCormack Oct 20 '12 at 11:46
  • The main reason is troubleshooting. – David Greenshtein Oct 20 '12 at 13:11

2 Answers2

0

You can use the following Socket constructor:

Socket(String remoteHost, int remotePort, InetAddress localAddress, int localPort)

or use Socket.bind() after socket creation.

See http://docs.oracle.com/javase/6/docs/api/java/net/Socket.html

Alastair McCormack
  • 26,573
  • 8
  • 77
  • 100
0

Forgetting the language/library for the moment... You define the local address and/or local port for a connecting socket the same way you do for a listening socket. You bind() the socket to whatever IP address and/or port you wish. Not binding is the same as binding to zero values.

When the value is zero, the OS will pick for you: For the address, it will bind to the address of the interface used to send to the destination. For the port, it will pick a non-privileged port (>1023) that is currently unused.

Brian White
  • 8,332
  • 2
  • 43
  • 67