在建立完ServerSocket對象後
Socket類和ServerSocket類都有兩個得到輸入輸出流的方法
package server;
import
import java
public class HttpEchoServer extends Thread
{
private Socket socket;
public void run()
{
try
{
InputStreamReader isr = new InputStreamReader(socket
BufferedReader br = new BufferedReader(isr);
OutputStreamWriter osw = new OutputStreamWriter(socket
osw
String s =
while (!(s = br
osw
osw
socket
}
catch (Exception e)
{
}
}
public HttpEchoServer(Socket socket)
{
this
}
public static void main(String[] args) throws Exception
{
ServerSocket serverSocket = new ServerSocket(
System
while (true)
{
Socket socket = serverSocket
new HttpEchoServer(socket)
}
}
}
編譯並運行HttpEchoServer後
圖
上面的代碼並未驗證HTTP請求類型
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26446.html