• Post Reply Bookmark Topic Watch Topic
  • New Topic

InetAddress!  RSS feed

 
Angela Jessi
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
 
huaqing liu
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
 
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");
}

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

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!