aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes question regarding server socket if server socket is other machine Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "question regarding server socket if server socket is other machine" Watch "question regarding server socket if server socket is other machine" New topic
Author

question regarding server socket if server socket is other machine

rakesh kadulkar
Ranch Hand

Joined: Jul 24, 2008
Posts: 115
Hi,
I am trying to create a simple chat application that will run on two instances of command promp.
If I run the program on single machine there is o problem, it works fine.

Now he problem is I am in a LAN enviroment.

Suppose there are two machines and i want one machine to run server socket and other to run client socket.

Now for server socket there is no issue as I will simple create a server socket using \



Now the ServerSocket will run on one machine.

But now the problem is i want to connect to this server socket using other machine.

So how can I achieve this. Because there is no method provided in the InetAddress class where I can eplicitly pass the Ip address of the machine that is running server socket.


"Also I nees to know what is the meaning of Raw IP address "

Rakesh Kadulkar
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19760
    
  20

Sure there is - the static getByXXX methods.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
rakesh kadulkar
Ranch Hand

Joined: Jul 24, 2008
Posts: 115
Yes the problem is solved but as such there is no static getByXXX method which directly takes the IP
address of some other machine. We have to take the IP address in a byte array and then pass this byte array in

InetAddress.getByAddress(byteArray)

Now there is no issue till now but there will be when I will start enhancing that code with a proper GUI
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19760
    
  20

getByName also accepts IP addresses in String format.
rakesh kadulkar
Ranch Hand

Joined: Jul 24, 2008
Posts: 115
well that is correct.
The method signature confused me.
It says getByName(String host). I thought ther emust be a name assigned to the host.

Well now it works fine .
Thanks you.
Paul Santa Maria
Ranch Hand

Joined: Feb 24, 2004
Posts: 236
Type in these two examples:

Simple Java.net "Hello World"

There is absolutely no practical difference if you ran the client and server in two different windows ... or on two completely different machines.

And as you also see, you pass the remote hostname (or IP address - it doesn't matter) from the command line when you invoke the program.

Instead of a command line argument from "main (String[] args)", you could, of course just as easily read the server name from a GUI: it doesn't matter.

Finally "raw IP" (in the context I believe you're asking), is simply the numeric ID (e.g. "127.0.01"), instead of a meaningful hostname (e.g. "localhost").

'Hope that helps .. PSM


Paul M. Santa Maria, SCJP
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: question regarding server socket if server socket is other machine