FileDocCategorySizeDatePackage
StartSocket.javaAPI DocAzureus 3.0.3.43210Fri Jun 15 11:38:14 BST 2007org.gudy.azureus2.ui.swt

StartSocket

public class StartSocket extends Object

Fields Summary
private final String[]
args
Constructors Summary
public StartSocket(String[] _args)

    	this.args = _args;
    
Methods Summary
public static voidmain(java.lang.String[] args)

      new StartSocket(args);
    
public booleansendArgs()
Attempt to send args via socket connection.

return
true if successful, false if connection attempt failed

    	Socket sck = null;
    	PrintWriter pw = null;
    	try {
    		String msg = "StartSocket: passing startup args to already-running Azureus java process listening on [127.0.0.1: 6880]";
    		
    			// DON'T USE LOGGER here as we DON't want to initialise all the logger stuff
    			// and in particular AEDiagnostics config dirty stuff!!!!
    		
    		System.out.println( msg );
       	
    		sck = new Socket("127.0.0.1", 6880);
         
    			// NOTE - this formatting is also used by AzureusCoreSingleInstanceClient and other org.gudy.azureus2.ui.common.Main.StartSocket
    		
    		pw = new PrintWriter(new OutputStreamWriter(sck.getOutputStream(),Constants.DEFAULT_ENCODING));
         
    		StringBuffer buffer = new StringBuffer(AzureusCoreSingleInstanceClient.ACCESS_STRING + ";args;");
         
    		for(int i = 0 ; i < args.length ; i++) {
    			String arg = args[i].replaceAll("&","&&").replaceAll(";","&;");
    			buffer.append(arg);
    			buffer.append(';");
    		}
      	 
    		pw.println(buffer.toString());
    		pw.flush();
    		
    		return true;
    	}
    	catch(Exception e) {
    		e.printStackTrace();
    		Debug.printStackTrace( e );
    		return false;  //there was a problem connecting to the socket
    	}
    	finally {
    		try {
    			if (pw != null)  pw.close();
    		}
    		catch (Exception e) {}
    		
    		try {
    			if (sck != null) 	sck.close();
    		}
    		catch (Exception e) {}
    	}