This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

InetAddress!

 
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
what is InetAddress and getLocalHost? If somebody can explain me with example. Do we have write IP address in InetAddress or not?
Thanks in advance,
Angela
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will this help?
Socket clientSocket=new Socket(hostname, portno);
InetAddress client=clientSocket.getInetAddress();
int port=clientSocket.getLocalPort();
good luck.
 
Angela Jessi
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi huaqing liu
Thanks for your help.
For example: I have server IP address is 10.3.158.154 and port number 10001.
Where I have to specify server IP address in following code.
Socket clientSocket=new Socket(hostname, portno);
InetAddress client=clientSocket.getInetAddress();
int port=clientSocket.getLocalPort();
let me know,
Angela
 
huaqing liu
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just put
Socket clientSocket=new Socket("10.3.158.154 ", 10001);
See if works.
Good luck.
Huaqing Liu
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public void init(){
try{
sock=new Socket(InetAddress.getLocalHost(),this.PORT);
read=new BufferedReader(new InputStreamReader(sock.getInputStream()));
print=new PrintWriter(sock.getOutputStream(),true);

}
catch(java.net.UnknownHostException uhexp){
System.out.println(uhexp.toString()+"HOST-CLIENT");
}
catch(java.io.IOException ioexp){
System.out.println(ioexp.toString()+"IO_CLIENT");
}

TheClient client=new TheClient();
}
 
maateen
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public void init(){
try{
sock=new Socket(InetAddress.getLocalHost(),this.PORT);
read=new BufferedReader(new InputStreamReader(sock.getInputStream()));
print=new PrintWriter(sock.getOutputStream(),true);

}
catch(java.net.UnknownHostException uhexp){
System.out.println(uhexp.toString()+"HOST-CLIENT");
}
catch(java.io.IOException ioexp){
System.out.println(ioexp.toString()+"IO_CLIENT");
}/*
try{
baseURL=new URL("http://"+this.getCodeBase().getHost()+":"+this.PORT+"/");
}
catch(java.net.MalformedURLException murlexp){
System.out.print(murlexp.toString());
}
try{
urlConn=baseURL.openConnection();
read=new BufferedReader(new InputStreamReader( urlConn.getInputStream()));
if (!urlConn.getDoOutput()) {
urlConn.setDoOutput(true);
}
print=new PrintWriter(urlConn.getOutputStream());
}
catch(java.io.IOException ioexp){
System.out.println(ioexp.toString()+this.ERROR+"READING");
}*/


TheClient client=new TheClient();
}
 
Angela Jessi
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Liu,
Thanks a lot for ur response.
So will this work?
Socket clientSocket=new Socket("10.3.158.154 ", 10001);
InetAddress client=clientSocket.getInetAddress();
int port=clientSocket.getLocalPort();
I have to put this in client program. AM I RIGHT?
Thanks in advance
Angela

Originally posted by huaqing liu:
Just put
Socket clientSocket=new Socket("10.3.158.154 ", 10001);
See if works.
Good luck.
Huaqing Liu


 
Tick check! Okay, I guess that was just an itch. Oh wait! Just a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic