import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
public class MyServer {
public static void main(String[] args) throws Exception {
ServerSocket server = new ServerSocket(4567, 30, InetAddress.getByName("localhost"));
Socket socket = server.accept();
OutputStream out = socket.getOutputStream();
InputStream is = new FileInputStream("1.html");
byte[] buf = new byte[1024];
int len = -1;
while( (len = is.read(buf)) > 0) {
out.write(buf, 0, len);
}
is.close();
out.close();
socket.close();
server.close();
}
}
|
|