Win a copy of Pipeline as Code this week in the Cloud/Virtualization 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

question regarding server socket if server socket is other machine

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 "
 
Sheriff
Posts: 22120
114
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure there is - the static getByXXX methods.
 
rakesh kadulkar
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22120
114
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
getByName also accepts IP addresses in String format.
 
rakesh kadulkar
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Won't you please? Please won't you be my neighbor? - Fred Rogers. Tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic