1 //header of class--------------------------------------------------------------- 2 import java.*; 3 import java.net.*; 4 import java.util.*; 5 6 abstract public class TCPService extends Service{ 7 private boolean stopservice; 8 protected Socket so; 9 10 abstract protected void serve(); 11 public final static int BUILD=141; 12 //run.zdys---------------------------------------------------------------------- 13 public void run(){ 14 if(so== null){ 15 init(); 16 try{ 17 int port= Integer.parseInt(arg[1]); 18 ServerSocket ss; 19 if(arg[2].equals("-")){ 20 ss= new ServerSocket(port); 21 }else{ 22 ss= new ServerSocket(port, 1000, InetAddress.getByName(arg[2])); 23 } 24 Utils.pr(this, "starting TCPService "+ arg[0]+ " on " 25 + ss.getInetAddress().getHostAddress()+ ":"+ ss.getLocalPort()); 26 ss.setSoTimeout(TIMEOUT); 27 while(true){ 28 Socket st; 29 try{ 30 st= ss.accept(); 31 }catch(java.io.InterruptedIOException ex2){ 32 if(stopservice){ 33 ss.close(); 34 Utils.pr(this, "TCPService "+ arg[0]+ " on " 35 + ss.getInetAddress().getHostAddress()+ ":"+ ss.getLocalPort()+ " stopped"); 36 return; 37 }else{ 38 continue; 39 } 40 } 41 TCPService r= (TCPService)this.getClass().newInstance(); 42 r.so= st; 43 r.arg= arg; 44 r.start(); 45 } 46 }catch(Exception ex){ 47 Utils.pr(this, "ERROR in TCPService.run:"+ ex); 48 } 49 }else{ 50 serve(); 51 } 52 } 53 //stopService.zdys-------------------------------------------------------------- 54 public void stopService(){ 55 stopservice= true; 56 } 57 //init.zdys--------------------------------------------------------------------- 58 public void init(){ 59 } 60 //end of class------------------------------------------------------------------ 61 }