package com.briup.webServer.v1;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;
public class ServerMain {
public static void main(String[] args) throws IOException {
System.out.println("hello");
ServerSocket ss = null;
Socket s = null;
BufferedReader in = null;
PrintStream out = null;
String path;
String i = null;
String []bs = null;
byte []b1 = new byte[1024*4];
BufferedReader br = null;
FileInputStream f1 = null;
FileInputStream f2 = null;
try {
f1 = new FileInputStream("files/index.html");
f2 = new FileInputStream("files/error.html");
ss = new ServerSocket(9999);
s = ss.accept();
in = new BufferedReader(new InputStreamReader(s.getInputStream()));
i=in.readLine();
System.out.println(i);
bs= i.split(" ");
for (String string : bs)
{
System.out.println(string);
}
out = new PrintStream(s.getOutputStream());
out.flush();
int j = - 1;
char[] b =new char[1024];
if (bs[0].equals("GET")&&bs[1].equals("/"))
{
while((j = in.read(b))!=-1) {
out.print(b);
}
}
String ip = s.getInetAddress().getHostAddress();
System.out.println("客户端ip:"+ip);
} catch (Exception e)
{
// TODO: handle exception
}finally
{
}
}
}
这代码没有什么实质内容,就是为了写一个程序而写一个程序。
你的目的是干啥呢 看不明白