?? netclient.java
字號(hào):
import java.io.*;
import java.net.*;
public class NetClient
{
public static final int PORT =8080;
public static void main(String[] args) throws IOException
{
InetAddress addr = InetAddress.getByName("localhost");
Socket socket =new Socket(addr,PORT);
try{
System.out.println("客戶端請(qǐng)求: "+socket);
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream())) ;
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())),true);
out.println("我想獲得一些信息");
out.println(" ");
System.out.println("客戶端請(qǐng)求發(fā)送完畢...");
String str = in.readLine();
System.out.println("接收: "+str);
while(str!=null){
str = in.readLine();
System.out.println("接收: "+str);
}
}finally{
System.out.println("客戶端關(guān)閉...");
socket.close();
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -