I have a legacy server application written in java which has been running fine over the last six years on a windows 2003 machine running Java 6.
We recently migrated the application to a brand new windows 2008 machine running the latest version of java.
Although the application seems to work fine, there is one weird issue
The code String remoteip=socket.getInetAddress().getHostAddress() seems to return the internet IP of the server machine instead of returning the IP of the remote client.
This was working properly on both Linux and Windows 2003 machines over the last 6-7 years.
To double check all settings, I set up a small php website on IIS and printed the value of REMOTE_ADDr variable. It printed the correct IP address of the client.
Any clues on what could be confusing the java app?
The Java doc says this:
getInetAddress()
Returns the local address of this server socket.
Probably previously you were running the server and the client on the same machine.
To be more specific: You probably have a ServerSocket(sSocket) waiting for connections from clients.
If you call sSocket.getInetAddress(), you will get the IP address of the server.
On the other hand, the role of a ServerSocket is to bind to a IP address and port and to wait for connections from clients. When such a connection is made, the sSocket.accept() method returns a Socket which represents the connection of the server to that specific client (cSocket). Calling cSocket.getRemoteAddress() returns the IP of the client
Related
I may be using my Java program (which is initialized by the simple Batch code at the bottom, which may or may not help anything). From my main computer which will connect to localhost to get to my MySql server.
I otherwise could be connecting via a laptop, which is on the same Wi-Fi network. Therefore, I believe it would use the IPv4 address. Lastly, I could connect via a completely different network and would use my IP.
How could I use Java to detect where exactly it is and change which host it will connect to while pinging the server?
java -jar thb.jar
pause
I have a Corba application in Java working on my PC. Both the client and server running on one PC. Now I want the server and client running on different PCs and establishing a connection between them but I'm not sure how to do it I tried looking for a solution online but no luck so far.
As long as you pass the object reference to your client you can put your server on any machine. You could pass the IOR as a stringified form (e.g. IOR:....) or as a corbaloc string.
For example see https://github.com/JacORB/JacORB/tree/master/demo/hello
I have created a test program between two virtual machines on my computer. So I have an RMI Server running on a virtual machine on VMware and I have an RMI Client running on another virtual machine on VMware.
I have set up SSL using SslRMIServerSocketFactory and SslRMIClientSocketFactory and it is possible to call methods from the client to the server, having the server to respond with the return value. So right now I have two Ubuntu machines running on VMware.
What happens is that the client makes the call to the server and I have to wait for about 17 seconds until the response from the server reaches the client and the print is executed on console. Updated: The method's call is fast. All this time is taken by the Registry.lookup() function.
Aren't 17 seconds too much time?
I know that VMs are slow by nature, plus the fact that SSL is running but still, aren't 17 seconds too much for what I am doing? The remote method only adds two integers and returns the result.
Thank you.
Java does reverse DNS when it either connects or accepts a socket, for security purposes. You didn't have any DNS or reverse DNS information about the server available at the client, or about the client available at the server. Putting a server entry into the client's /etc/hosts file and a client entry into the server's /etc/hosts file fixed that. Otherwise it would try via a DNS server and timeout waiting for a response before proceeding.
I had the same problem connecting my RMI client to the RMI server on the same machine.
In my case even the instantiation of an object inheriting from UnicastRemoteObject in the server caused a delay of more than 20 secs. Configuring /etc/hosts with localhost didn't fix the problem and I had to use this line in my java application before using RMI:
System.setProperty("java.rmi.server.hostname", "127.0.0.1");
I have a client/server applciation that communicates through JNDI/RMI/IIOP using, on client side, some Glassfish client code (NOT packaged as a Glassfish client) and on server side a Glassfish instance.
I have some Glassfish multimode scripts that I use to make sure the domains I create on any machines are totally identical and correctly configured.
Using that script on local network, I have already made sure I could access a remote Glassfish server instance from client code on my machine (that was quite a reasonable guess, however I tend to test all things I'm not totally sure of).
Next step is to have that client/server application working over (I should instead say "through") internet : with my client code in my company LAN (in other words on my machine) and my server code on an Amazon VM running my Glassfish server. For some reasons, the remote Glassfish is running on a Windows VM.
Obviously (as I ask that question, you can safely guess the through internet test is NOT working. And you're right.
So, to have more guesses, I started SmartSniffer both on my machine and on server.
On my machine, I can only see one TCP packet going to that server instance (and nothing coming back).
On server instance, I can see one packet entering (the client query) and one packet exiting (the server answer). That server answer looks like this :
[4/4/2012 11:47:13 AM:917]
GIOP.......(................NameService....._is_a...................NEO................ª.......(IDL:omg.org/SendingContext/CodeBase:1.0............n........172.27.63.145.Ô2....¯«Ë........e...........................
...................
... ...........&...............(IDL:omg.org/CosNaming/NamingContext:1.0.
That 172.27.63.145 address is my IP in local network.
[4/4/2012 11:47:13 AM:917]
GIOP.......2............NEO................0.......(IDL:omg.org/SendingContext/CodeBase:1.0............ô........46.137.114.###.'5....¯«Ë........d...........................
...................
... ...........&...........!...|...............$...
...f............10.241.42.###.'6.#........g..............g........default...................g...............+IDL:omg.org/CosNaming/NamingContextExt:1.0.............¢........10.241.42.208.'5...M¯«Ë....
...d... S1AS-ORB............RootPOA....
TNameService............................... ...................
... ...........&......
That 46.137.114.### is external one of my Amazon VM, and 10.241.42.### is its internal IP in amazon magical virtual server.
So it seems server is answering, no ?
But that answer never finds its way to my machine in my network.
So ... how can I check where it get lost ? Seems likepacket sniffer has done its job, but what can I do now ?
NOTE This question is a clarification of "How to Connect a glassfish client to glassfish server over NATs?"
Perhaps stupid question, but is your Amazon EC2 instance is configured with all required ports open for your communication protocol to work? You could see configured open ports in security group your instance assigned to in AWS console, under EC2->Security Groups.
I'm testing a client-server based Java application where a specific scenario involves having both the client and server running on the same host (i.e., the client connects to the server running on localhost). This seems to work fine except for when I test this scenario on a virtual machine (running 32bit Windows 7) using VirtualBox.
Note: Everything henceforth is running inside the virtual machine. I start the server and try to connect to it using the client but the connection times out. Surprisingly, I tried connecting to the server using putty and the connection behaved as expected. Both the Java client and putty tried to connect to localhost - the client failed but putty succeeded.
Does anyone have a possible explanation for why this might be happening?
Note: This is not a duplicate of Addressing localhost from a virtualbox virtual machine
How do you connect to the localhost? By connecting to the hostname "localhost"? You could try connecting to the InetAddress returned by getLocalHost()