?? netserver.java
字號:
import java.io.*;
import java.net.*;
public class NetServer
{
public static final int PORT =8080;
public static void main(String[] args) throws IOException
{
InetAddress addr = InetAddress.getByName("localhost");
ServerSocket s =new ServerSocket(PORT,10,addr);
System.out.println("虛擬Web服務器啟動: "+s);
try{
Socket socket =s.accept();
try{
System.out.println("接受客戶端連接請求: "+socket);
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream())) ;
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())),true);
String str = in.readLine();
System.out.println("收到: "+str);
while(!str.equals(" ")){
str = in.readLine();
System.out.println("收到: "+str);
}
out.println("客戶端傳送信息服務器已經接收完畢");
System.out.println("服務器響應完畢,正在退出...");
}finally{
System.out.println("服務器關閉...");
socket.close();
}
}finally{
s.close();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -