?? server.java
字號:
import java.net.*;
import java.io.*;
/**
* Description:
* <br/>Copyright (C), 2008-2010, Yeeku.H.Lee
* <br/>This program is protected by copyright laws.
* <br/>Program Name:
* <br/>Date:
* @author Yeeku.H.Lee kongyeeku@163.com
* @version 1.0
*/
public class Server
{
public static void main(String[] args)
throws IOException
{
//創建一個ServerSocket,用于監聽客戶端Socket的連接請求
ServerSocket ss = new ServerSocket(30000);
//采用循環不斷接受來自客戶端的請求
while (true)
{
//每當接受到客戶端Socket的請求,服務器端也對應產生一個Socket
Socket s = ss.accept();
//將Socket對應的輸出流包裝成PrintStream
PrintStream ps = new PrintStream(s.getOutputStream());
//進行普通IO操作
ps.println("您好,您收到了服務器的新年祝福!");
//關閉輸出流,關閉Socket
ps.close();
s.close();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -