listensocket.java
上传用户:lybcsm
上传日期:2007-04-26
资源大小:26k
文件大小:1k
- package ftpserver;
- import java.io.*;
- import java.lang.*;
- import java.util.*;
- import java.net.*;
- public class listensocket implements Runnable {
- private boolean blnRunning;
- private ServerSocket serversocket;
- private Socket clientsocket;
- private ftpframe frame;
- private String linesep;
- //Constructor
- public listensocket(ServerSocket serversocket,ftpframe frame){
- this.serversocket =serversocket;
- this.frame=frame;
- //Line Separator
- linesep=System.getProperty("line.separator");
- Thread thread=new Thread(this);
- thread.start();
- }
- public void setRunning(boolean isRunning){
- blnRunning=isRunning;
- }
- public boolean getRunning(){
- return blnRunning;
- }
- public void run(){
- while(true){
- if(blnRunning){
- try{
- Socket clientsocket=serversocket.accept();
- String sMsg="Connection from "+
- clientsocket.getInetAddress().getHostAddress();
- frame.textMessage .append(sMsg+linesep);
- System.out.println(sMsg);
- Thread thread=new Thread(new ftpsession(clientsocket,frame));
- thread.start();
- }
- catch(Exception ex){
- frame.textMessage .append(ex.getMessage()+linesep);
- System.out.println(ex.getMessage());
- }
- }
- try{Thread.sleep(500);}
- catch(Exception ex){}
- }
- }
- }