import java.io.*;
import java.net.*;
class myThread implements Runnable
{
private Socket s;
public myThread(Socket s)
{
this.s=s;
}
public void run()
{
try
{
System.out.println(s.getInetAddress().getHostAddress()+".......conneted");
BufferedReader fr=new BufferedReader(new FileReader("1.html"));
PrintWriter w=new PrintWriter(s.getOutputStream(),true);
String line=null;
while((line=fr.readLine())!=null)
{
w.println(line);
}
s.close();
}
catch(Exception e)
{
System.out.println("服务端错误");
}
}
}
class ServerDemo
{
public static void main(String[] arge) throws Exception
{
ServerSocket sk=new ServerSocket(11000);
while(true)
{
Socket s=sk.accept();
new Thread(new myThread(s)).start();
}
}
}
运行该服务器,在浏览器地址栏输入服务器的IP和端口,例如http:\\192.168.1.19:11000即可访问到服务器返回来的信息