Package java.net

Examples of java.net.Socket


     * @return the new transfer object
     */
    public Transfer openNewConnection() throws IOException {
        InetAddress address = socket.getInetAddress();
        int port = socket.getPort();
        Socket s2 = NetUtils.createSocket(address, port, ssl);
        Transfer trans = new Transfer(null);
        trans.setSocket(s2);
        trans.setSSL(ssl);
        return trans;
    }
View Full Code Here


    InetAddress    address )
 
    throws NetworkAdminException
  {
    try{
      Socket  socket = new Socket();
     
      int  timeout = TIMEOUT;
       
      long  start = SystemTime.getCurrentTime();
     
      socket.connect( new InetSocketAddress( WHOIS_ADDRESS, WHOIS_PORT ), timeout );
   
      long  end = SystemTime.getCurrentTime();
     
      timeout -= (end - start );
     
      if ( timeout <= 0 ){
       
        throw( new NetworkAdminException( "Timeout on connect" ));
       
      }else if ( timeout > TIMEOUT ){
       
        timeout = TIMEOUT;
      }
     
      socket.setSoTimeout( timeout );
     
      try{
        OutputStream  os = socket.getOutputStream();
       
        String  command = "-u -p " + address.getHostAddress() + "\r\n";
       
        os.write( command.getBytes());
       
        os.flush();
       
        InputStream  is = socket.getInputStream();
       
        byte[]  buffer = new byte[1024];
       
        String  result = "";
       
        while( true ){
         
          int  len = is.read( buffer );
         
          if ( len <= 0 ){
           
            break;
          }
         
          result += new String( buffer, 0, len );
        }

        return( processResult( result ));

      }finally{
       
        socket.close();
      }
    }catch( Throwable e ){
     
      throw( new NetworkAdminException( "whois connection failed", e ));
   
View Full Code Here

     * @throws ComponentException if an error happens during the connection and authentication steps.
     */
    public void connect(String host, int port, String subdomain) throws ComponentException {
        try {
            // Open a socket to the server
            this.socket = new Socket();
            socket.connect(new InetSocketAddress(host, port), manager.getConnectTimeout());
            if (manager.getServerName() != null) {
                this.domain = subdomain + "." + manager.getServerName();
            }
            else {
View Full Code Here

     
      sockets.add( socket1 );
    }

    try{
      Socket socket2 = new Socket( source_host, source_port );
 
      synchronized( this ){

        if ( destroyed ){
         
          try{
            socket1.close();
           
          }catch( Throwable e ){       
          }
         
          try{
            socket2.close();
           
          }catch( Throwable e ){       
          }
         
          sockets.remove( socket1 );
         
          return;
        }
       
        sockets.add( socket2 );
      }
     
      handlePipe( socket1.getInputStream(), socket2.getOutputStream());
     
      handlePipe( socket2.getInputStream(), socket1.getOutputStream());
     
    }catch( Throwable e ){
     
      try{
        socket1.close();
View Full Code Here

              InetAddress inet_address = server_selector.getBoundToAddress();
              try
              {
                if (inet_address == null)
                  inet_address = InetAddress.getByName("127.0.0.1"); //failback
                Socket sock = new Socket(inet_address, tcp_listen_port, inet_address, 0);
                sock.close();
                listenFailCounts[i] = 0;
              } catch (Throwable t)
              {
                //ok, let's try again without the explicit local bind
                try
                {
                  Socket sock = new Socket(InetAddress.getByName("127.0.0.1"), tcp_listen_port);
                  sock.close();
                  listenFailCounts[i] = 0;
                } catch (Throwable x)
                {
                  listenFailCounts[i]++;
                  Debug.out(new Date() + ": listen port on [" + inet_address + ": " + tcp_listen_port + "] seems CLOSED [" + listenFailCounts[i] + "x]");
View Full Code Here

                new Runnable()
                {
                  public void
                  run()
                  {
                    Socket socket = new Socket();
                   
                    String  result = a_str;
                   
                    try{
                      socket.bind( new InetSocketAddress( ia, 0 ));
                                               
                      socket.connectnew InetSocketAddress( "www.google.com", 80 ), 10*1000 );
                     
                      result += "*";
                     
                    }catch( Throwable e ){
                     
                    }finally{
                      try{
                        socket.close();
                      }catch( Throwable e ){
                      }
                     
                    }
                   
View Full Code Here

      run()
      {
        while( !destroyed ){
         
          try{
            final Socket  socket = server_socket.accept();
           
            connection_speed.addValue( 1 );
           
            new AEThread2( "TranscodePipe", true )
            {
View Full Code Here

   * @param address the server address.
   * @param command the first command sent to the server ({@link IndexServer#GET_CLIENT_INPUT_STREAM},
   * {@link IndexServer#GET_INDEX_READER}, &hellip;).
   */
  public RemoteIndexServerConnection( final SocketAddress address, final byte command ) throws IOException {
    socket = new Socket();
    socket.connect( address );
    inputStream = new DataInputStream( new FastBufferedInputStream( socket.getInputStream() ) );
    outputStream = new DataOutputStream( new FastBufferedOutputStream( socket.getOutputStream() ) );
    outputStream.writeByte( command );
    outputStream.flush();
View Full Code Here

    * @param randomAccess whether the index should be accessible randomly.
   * @param documentSizes if true, document sizes will be loaded (note that sometimes document sizes
   * might be loaded anyway because the compression method for positions requires it).
   */
  public static Index getIndex( final String host, final int port, final boolean randomAccess, final boolean documentSizes ) throws IOException, ClassNotFoundException {
    final Socket socket = new Socket( host, port == -1 ? DEFAULT_PORT : port );
    LOGGER.debug( "Accessing remote index at " + host + ":" + port + "..." );
    final DataOutputStream outputStream = new DataOutputStream( socket.getOutputStream() );
    outputStream.writeByte( GET_INDEX );
    outputStream.writeBoolean( randomAccess );
    outputStream.writeBoolean( documentSizes );
    outputStream.flush();
    Index index = (Index)BinIO.loadObject( socket.getInputStream() );
    socket.close();
    LOGGER.debug( "Index at " + socket + " downloaded: " + index );
    return index;
  }
View Full Code Here

   */

  public static void start( final Index index, final ServerSocket serverSocket, boolean forceRemoteIndex ) throws IOException {
    LOGGER.info( "Index server started at " + serverSocket.getLocalSocketAddress() );
    ThreadPoolExecutor threadPool = (ThreadPoolExecutor)Executors.newCachedThreadPool();
    Socket socket;
    final SocketAddress localSocketAddress = serverSocket.getLocalSocketAddress();
    int command;
    for ( ;; ) {
     
      socket = serverSocket.accept();
      command = socket.getInputStream().read();
      LOGGER.debug( "Remote command: " + command );
     
      switch( command ) {
      case GET_INDEX:
        DataInputStream dis = new DataInputStream( socket.getInputStream() );
        DataOutputStream dos = new DataOutputStream( socket.getOutputStream() );
        boolean randomAccess = dis.readBoolean();
        boolean documentSizes = dis.readBoolean();
       
        if ( index instanceof BitStreamIndex && ! forceRemoteIndex ) {
          BitStreamIndex localIndex = (BitStreamIndex)index;
View Full Code Here

TOP

Related Classes of java.net.Socket

Copyright © 2018 www.massapicom. 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.