zoukankan      html  css  js  c++  java
  • 2014--9=17 软工二班 MyEclipse blue==4

    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("asdfasdf");
                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;    
        
        }
    
    }
  • 相关阅读:
    深入 聚集索引与非聚集索引(一)
    mysql 忘记root密码(linux ok, windows 没试)
    (转)关于中国的互联网
    log4j:启动tomcat发现 log4j:WARN No appenders could be found for logger 解决办法 转载
    log4j
    书签
    高级数据模型
    silverlight第三方控件
    实体框架资源
    RIASilverlight 程序开发框架3
  • 原文地址:https://www.cnblogs.com/fantasy12436109/p/3977735.html
Copyright © 2011-2022 走看看