JAVA學習筆記-----------InetAddress 的有關IP地址的使用案例(雜亂)

OneCode2World發表於2015-08-05
package com.package_Server;
import java.io.*;
import java.net.*;
import java.awt.*;
public class Server_test 
{
  
public static void main(String[] args)
{
Server_test st=new Server_test();


}

public Server_test()
  {


try {
byte[] bs=new byte[]{(byte)192,(byte)168,120,54};
System.out.println(InetAddress.getByAddress(bs));
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}



/*try {
            InetAddress addr = InetAddress.getByName("127.0.0.1");
            System.out.println(addr.toString());
            System.out.println(InetAddress.getByName(addr.getHostName()) == addr);
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }這個可以正常執行*/
        
       /* try {
InetAddress addr = InetAddress.getByName("192.168.120.54");
String IP=addr.toString();
System.out.println(IP);
System.out.println(addr.toString());
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
*/



        
/*try {
String ip="192.168.120.54";
InetAddress addr=InetAddress.getByName(ip);
String IP=addr.toString();
} catch (UnknownHostException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println(addr);
*/
/*try {
// 建立一個伺服器套接字
  ServerSocket ss=new ServerSocket(9999);
  
  //讓伺服器套接字處於監聽狀態
  Socket s=ss.accept();
  
  //獲取套接字輸入輸出流,並建立管道
//StringBufferInputStream  isr=new StringBufferInputStream(s.getInputStream());
//InputStream isr=s.getInputStream();// 正確!
  InputStreamReader isr=new InputStreamReader(s.getInputStream());
  
  BufferedReader br=new BufferedReader(isr);
  String info=br.readLine();
  System.out.println("你好");
  
  System.out.println(info);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
  }*/

  }
}

相關文章