baiyunjn 发表于 2017-1-28 14:58:31

tomcat启动soket程序

Socket socket = null;
    public void init() throws ServletException {
      // Put your code here
                  socketThread sthread = new socketThread();
             sthread.start();
                  socket = sthread.getSocket();
    }
socketThread类
public socketThread extends Thread{
    private static Socket s = null;
    public void run()
    {
      try
      {
            ServerSocket listener = new ServerSocket(port);
            while(true){
               //相关业务
                   s = listener.accept();
            }
      }catch(Exception ex){
         
      }
    }
    public Socket getSocket(){
         return s;
    }
}
页: [1]
查看完整版本: tomcat启动soket程序