Examples of Socket


Examples of java.net.Socket

  {
    bContinue = true;
    while (bContinue) {
      BufferedReader br = null;
      try {
        Socket sck = socket.accept();
        String address = sck.getInetAddress().getHostAddress();
        if (address.equals("localhost") || address.equals("127.0.0.1")) {
          br = new BufferedReader(new InputStreamReader(sck.getInputStream(),Constants.DEFAULT_ENCODING));
          String line = br.readLine();
          //System.out.println("received : " + line);
         
          if (Logger.isEnabled())
            Logger.log(new LogEvent(LOGID, "Main::startServer: received '"
                + line + "'"));
        
          if (line != null) {
            String [] args = parseArgs(line);
            if (args != null && args.length > 0) {
              String debug_str = args[0];
              for (int i=1; i<args.length; i++) {
                debug_str += " ; " + args[i];
              }
              Logger.log(new LogEvent(LOGID, "Main::startServer: decoded to '" + debug_str + "'"));
              processArgs(core,args);
            }
          }
        }
        sck.close();

      }
      catch (Exception e) {
        if(!(e instanceof SocketException))
          Debug.printStackTrace( e );     
View Full Code Here

Examples of java.net.Socket

        return openSocket(sockAddr, connectTimeout, POLL_DELAY, maxRetry);
    }

    public static Socket openSocket(SocketAddress sockAddr, int connectTimeout, long pollDelay, int maxRetry)
            throws IOException {
        Socket socket = new Socket();
        return openSocket(socket, sockAddr, connectTimeout, pollDelay, maxRetry);
    }
View Full Code Here

Examples of java.net.Socket

            ch.configureBlocking(blocking);
        } catch (IOException e) {
            LOG.error("Failed to open SocketChannel.", e);
            throw new IllegalStateException(e);
        }
        final Socket sock = ch.socket();
        if(rcvbufSize != -1) {
            try {
                sock.setReceiveBufferSize(rcvbufSize);
            } catch (SocketException e) {
                LOG.error("Failed to setReceiveBufferSize.", e);
                throw new IllegalStateException(e);
            }
        }
View Full Code Here

Examples of java.net.Socket

                    throw new Exception( "Invalid Password!" );
                }
            }

            // Open the connection.
            Socket socket = new Socket( InetAddress.getByName( host ), Integer.parseInt( port ) );

            // Capture the information about the connection.
            ConnectionInfo connectionInfo = new ConnectionInfo(
                    user,
                    request.getRemoteHost(),
                    host,
                    port,
                    socket,
                    new Date(),
                    socket.getInputStream(),
                    socket.getOutputStream() );

            // Add the connection to the manager.
            connectionManager.addConnection( connectionInfo );

            log.info( "Connection Opened: " + connectionInfo.toString() );
View Full Code Here

Examples of java.net.Socket

    long  failed_accepts    = 0;
   
    while( !closed ){
     
      try{       
        Socket socket = ss.accept();
         
        successfull_accepts++;
       
        String  ip = socket.getInetAddress().getHostAddress();
               
        if ( (!isIPFilterEnabled()) || (!ip_filter.isInRange( ip, "Tracker", null ))){
         
          runProcessor( new TRBlockingServerProcessor( this, socket ));
         
        }else{
         
          socket.close();
        }
       
      }catch( Throwable e ){
       
        if ( !closed ){
View Full Code Here

Examples of java.net.Socket

    /**
     * Attempt to send args via socket connection.
     * @return true if successful, false if connection attempt failed
     */
    public boolean sendArgs() {
      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 != nullpw.close();
        }
        catch (Exception e) {}
       
        try {
          if (sck != null)   sck.close();
        }
        catch (Exception e) {}
      }
    }
View Full Code Here

Examples of java.net.Socket

  public void run() {
    bContinue = true;
    while (bContinue) {
      BufferedReader br = null;
      try {
        Socket sck = socket.accept();
        String address = sck.getInetAddress().getHostAddress();
        if (address.equals("localhost") || address.equals("127.0.0.1")) {
          br = new BufferedReader(new InputStreamReader(sck.getInputStream()));
          String line = br.readLine();
          //System.out.println("received : " + line);
          if (line != null) {
            //            main.showMainWindow();
            StringTokenizer st = new StringTokenizer(line, ";");
            List argsList = new ArrayList();
            while( st.hasMoreElements() )
              argsList.add(st.nextToken().replaceAll("&;", ";").replaceAll("&&", "&"));
            if (argsList.size() > 1 )
            {
              String checker = (String) argsList.remove(0);
              if (checker.equals(AzureusCoreSingleInstanceClient.ACCESS_STRING)) {
                if (argsList.get(0).equals("args")) {
                  argsList.remove(0);                 
                  String newargs[] = new String[argsList.size()];
                  argsList.toArray(newargs);
                  Main.processArgs(newargs, null, null);
                } else {
                  Logger.getLogger("azureus2").error("Something strange was sent to the StartServer: " + line);
                }
              } else {
        Logger.getLogger("azureus2").error("StartServer: Wrong access token.");
              }
            }
          }
        }
        sck.close();

      } catch (Exception e) {
        if (!(e instanceof SocketException))
          e.printStackTrace();
        bContinue = false;
View Full Code Here

Examples of java.net.Socket

      }
    }.start();
   
    while( true ) {
      try {
        Socket socket = serverSocket.accept();
       
        InetSocketAddress addr = (InetSocketAddress) socket.getRemoteSocketAddress();
       
        if( addr.isUnresolved() || ! isAllowed(addr) ) {
          System.out.println("TelnetUI: rejecting connection from: " + addr + " as address is not allowed");
          socket.close();
        }
        else {
          System.out.println("TelnetUI: accepting connection from: " + addr);
          int loginAttempts = 0;
         
          while( true ) {
            // TODO: might want to put this in another thread so the port doesnt block while the user logs in
           
            //System.out.println("TelnetUI: starting login" );
           
            UserProfile profile = login( socket.getInputStream(), socket.getOutputStream() );
           
            //System.out.println("TelnetUI: login profile obtained" );
           
            if( profile != null ) {
             
              //System.out.println("TelnetUI: creating console input" );
             
              ui.createNewConsoleInput("Telnet Console " + threadNum++, socket.getInputStream(), new PrintStream(socket.getOutputStream()), profile);
              break;
            }
           
            //System.out.println("TelnetUI: failed to obtain login profile" );
           
            loginAttempts++;
           
            if( loginAttempts >= maxLoginAttempts ) {
              System.out.println("TelnetUI: rejecting connection from: " + addr + " as number of failed connections > max login attempts (" + maxLoginAttempts + ")");
              socket.close();
              break;
            }
          }
        }
      }
View Full Code Here

Examples of java.net.Socket

    }
  }
 
  public static class StartSocket {
    public StartSocket(String args[]) {
      Socket sck = null;
      PrintWriter pw = null;
      try {
        System.out.println("StartSocket: passing startup args to already-running process.");
       
    // NOTE - this formatting is also used by AzureusCoreSingleInstanceClient and other org.gudy.azureus2.ui.swt.StartSocket
       
        sck = new Socket("127.0.0.1",6880);
        pw = new PrintWriter(new OutputStreamWriter(sck.getOutputStream()));
        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();
      } catch(Exception e) {
        e.printStackTrace();
      } finally {
        try {
          if (pw != null)
            pw.close();
        } catch (Exception e) {
        }
        try {
          if (sck != null)
            sck.close();
        } catch (Exception e) {
        }
      }
    }
View Full Code Here

Examples of java.net.Socket

  void notifyConnected () {
    if (INFO) {
      SocketChannel socketChannel = tcp.socketChannel;
      if (socketChannel != null) {
        Socket socket = tcp.socketChannel.socket();
        if (socket != null) {
          InetSocketAddress remoteSocketAddress = (InetSocketAddress)socket.getRemoteSocketAddress();
          if (remoteSocketAddress != null) info("kryonet", this + " connected: " + remoteSocketAddress.getAddress());
        }
      }
    }
    Listener[] listeners = this.listeners;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.