• 2014--9=17 软工二班 MyEclipse blue==5


    package cn.rwkj.test;
    
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.io.PrintWriter;
    import java.net.ServerSocket;
    import java.net.Socket;
    
    
    
    public class TestSocket {
        private Socket sock=null ;
        private static ServerSocket server =null;
        private static int port=8080 ;
        
        public  TestSocket() {       //定义一个方法
            
            try {
                System.out.println("a");
                
                server=new ServerSocket(port);
                sock=server.accept();
                
                System.out.println("ip:" + sock.getInetAddress());
                InputStream in = sock.getInputStream();
                
                String str = getString(in);
                
                System.out.println(str);
                
                
                
                OutputStream    out=    sock.getOutputStream();
                
                PrintWriter write=new PrintWriter(out);
                write.println("HTTP/1.0.200  OK");
                write.println("Content-type:/html; charset:gbk");
                
                write.println();
    write.println("<div  style='300px ; height:300px ; background:#FF0000' >  asdfasdf  </div>");
                write.close();
                
                
                
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            
            
        }
        
        public static void main(String []args){
            new TestSocket();        
        }
        
        
        public Socket getSock() {
            return sock;
        }
        public void setSock(Socket sock) {
            this.sock = sock;
        }
        public ServerSocket getServer() {
            return server;
        }
        public void setServer(ServerSocket server) {
            this.server = server;
        }
        
        public String getString(InputStream in) throws IOException{
            
            String str="";
            byte []    b=new byte[1024];
        int len=-1;
        while(   (len = in.read(b) )!=-1  ) {
            System.out.println(len);
            str = new String(b) ;
            break;
        }
        return str;    
        
        }
    
    }

  • 相关阅读:
    最短路
    P2863 [USACO06JAN]牛的舞会The Cow Prom
    牛客小白月赛12
    牛客练习赛41
    求余
    dreamstart 的催促
    deepin安装tesseract出错,tesserocr.cpp:653:10: fatal error: leptonica/allheaders.h: 没有那个文件或目录
    自动抽屉 + 点赞 + 取消赞
    爬取汽车之家
    css垂直居中和水平居中
  • 原文地址:https://www.cnblogs.com/fantasy12436109/p/3977755.html
Copyright © 2020-2023  润新知