listensocket.java~2~
上传用户:lybcsm
上传日期:2007-04-26
资源大小:26k
文件大小:1k
源码类别:

Ftp服务器

开发平台:

Java

  1. package ftpserver;
  2. import java.io.*;
  3. import java.lang.*;
  4. import java.util.*;
  5. import java.net.*;
  6. public class listensocket implements Runnable {
  7.      private boolean blnRunning;
  8.      private ServerSocket serversocket;
  9.      private Socket clientsocket;
  10.      private ftpframe frame;
  11.      private String linesep;
  12.      //Constructor
  13.      public listensocket(ServerSocket serversocket,ftpframe frame){
  14.          this.serversocket =serversocket;
  15.          this.frame=frame;
  16.          //Line Separator
  17.          linesep=System.getProperty("line.separator");
  18.          Thread thread=new Thread(this);
  19.          thread.start();
  20.        }
  21.      public void setRunning(boolean isRunning){
  22.         blnRunning=isRunning;
  23.       }
  24.      public boolean getRunning(){
  25.         return blnRunning;
  26.       }
  27.      public void run(){
  28.         while(true){
  29.            if(blnRunning){
  30.               try{
  31.                  Socket clientsocket=serversocket.accept();
  32.               String sMsg="Connection from "+
  33.               clientsocket.getInetAddress().getHostAddress();
  34.               frame.jLog.append(sMsg+linesep);
  35.               System.out.println(sMsg);
  36.               Thread thread=new Thread(new ftpsession(clientsocket,frame));
  37.               thread.start();
  38.             }
  39.             catch(Exception ex){
  40.                frame.jLog.append(ex.getMessage()+linesep);
  41.                System.out.println(ex.getMessage());
  42.              }
  43.            }
  44.          try{Thread.sleep(500);}
  45.          catch(Exception ex){}
  46.        }
  47.      }
  48. }