我也在研究,是否多客户情况server必须多线程

解决方案 »

  1.   

    server必须多线程 ,客户端不用
      

  2.   

    客户一般都是单线程(如果只是专门用于连接一个SERVER),当然你要开多进/线程也没人杀你。
    服务器根据负载可以是:
    单进程,多进程,多线程。
    三者处理并发请求的能力递增。
      

  3.   

    public void start() 
    {
       if ( myThread !=null) {
          myThread.stop();
          myThread=null;
       }
       if ( myThread ==null) {
          myThread=new Thread(this);
       }
       try {
    sock=new Socket(hostName,portno);
       }
       catch(IOException e){
             System.out.println("socket error!" + e);
       };
       try {
    is = new DataInputStream(sock.getInputStream());
       }        
       catch(IOException e){
             System.out.println("in error!" + e);
       };
       try {
             os = new DataOutputStream(sock.getOutputStream());
       }
       catch(IOException e){
             System.out.println("out error!" + e);
       };
       myThread.start();
    }
    public void end()
    {
       myThread = null;                
    }public void run()
    {
       ...
    }