?? myclient.java
字號:
import java.net.*;
import java.io.*;
// 這個是客戶端程序
public class myClient
{
public static void main(String[] args)
throws Exception
{
// 我們通過本機測試這個程序,所以用null表示本機
// 得到本機ip
InetAddress addr = InetAddress.getByName(null);
// 下面的語句和上面的是等效的
// InetAddress addr = InetAddress.getByName("localhost");
// InetAddress addr = InetAddress.getByName("127.0.0.1");
System.out.println("這臺機子的ip地址是:"+addr);
// 請求和服務器建立一個socket連接
Socket socket = new Socket(addr, myServer.PORT);
try{
System.out.println("套接字(socket) = " + socket);
BufferedReader in =
new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter out =
new PrintWriter(
new BufferedWriter(
new OutputStreamWriter(socket.getOutputStream())),true);
for(int i=0; i<5; i++){
out.println("你好"+i);
String str = in.readLine();
System.out.println(str);
}
out.println("END");
}
catch(IOException e){
System.out.println(e.toString());
}
finally{
System.out.println("closing...");
socket.close();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -