?????JAVA 2017-08-21 11:53 采纳率: 25%
浏览 640

不会写http的有关东西,刚刚学习 还望大神给我详细介绍这个,谢谢大家

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 
    {


    }

}

}

  • 写回答

2条回答

  • devmiao 2017-08-22 01:44
    关注

    这代码没有什么实质内容,就是为了写一个程序而写一个程序。

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器