Package java.net

Examples of java.net.Socket


                        ssoc.setEnabledCipherSuites(ssl.getEnabledCipherSuites());
                    }
                    dataSoc = ssoc;
                } else {
                    LOG.debug("Opening active data connection");
                    dataSoc = new Socket();
                }

                dataSoc.setReuseAddress(true);

                InetAddress localAddr = resolveAddress(dataConfig
                        .getActiveLocalAddress());

                // if no local address has been configured, make sure we use the same as the client connects from
                if(localAddr == null) {
                    localAddr = ((InetSocketAddress)session.getLocalAddress()).getAddress();
                }      

                SocketAddress localSocketAddress = new InetSocketAddress(localAddr, dataConfig.getActiveLocalPort());
               
                LOG.debug("Binding active data connection to {}", localSocketAddress);
                dataSoc.bind(localSocketAddress);

                dataSoc.connect(new InetSocketAddress(address, port));
            } else {

                if (secure) {
                    LOG.debug("Opening secure passive data connection");
                    // this is where we wrap the unsecured socket as a SSLSocket. This is
                    // due to the JVM bug described in FTPSERVER-241.

                    // get server socket factory
                    SslConfiguration ssl = getSslConfiguration();
                   
                    // we've already checked this, but let's do it again
                    if (ssl == null) {
                        throw new FtpException(
                                "Data connection SSL not configured");
                    }

                    SSLSocketFactory ssocketFactory = ssl.getSocketFactory();

                    Socket serverSocket = servSoc.accept();

                    SSLSocket sslSocket = (SSLSocket) ssocketFactory
                            .createSocket(serverSocket, serverSocket
                                    .getInetAddress().getHostAddress(),
                                    serverSocket.getPort(), true);
                    sslSocket.setUseClientMode(false);

                    // initialize server socket
                    if (ssl.getClientAuth() == ClientAuth.NEED) {
                        sslSocket.setNeedClientAuth(true);
View Full Code Here


public class Start {
    public Start(String args[]) {
//      if(args.length == 0)
//        return;

      Socket sck = null;
      PrintWriter pw = null;
      try {         
        System.out.println("StartSocket: passing startup args to already-running Azureus java process.");
       
        sck = new Socket("127.0.0.1", 6880);
       
        pw = new PrintWriter(new OutputStreamWriter(sck.getOutputStream(),"UTF8"));
       
        StringBuffer buffer = new StringBuffer("Azureus Start Server Access;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) {
        Debug.printStackTrace( e );
      } finally {
        try {
          if (pw != null)
            pw.close();
        } catch (Exception e) {
        }
        try {
          if (sck != null)
            sck.close();
        } catch (Exception e) {
        }
      }
    }
View Full Code Here

     */
    private InputStream getDataInputStream() throws IOException {
        try {

            // get data socket
            Socket dataSoc = socket;
            if (dataSoc == null) {
                throw new IOException("Cannot open data connection.");
            }

            // create input stream
            InputStream is = dataSoc.getInputStream();
            if (factory.isZipMode()) {
                is = new InflaterInputStream(is);
            }
            return is;
        } catch (IOException ex) {
View Full Code Here

     */
    private OutputStream getDataOutputStream() throws IOException {
        try {

            // get data socket
            Socket dataSoc = socket;
            if (dataSoc == null) {
                throw new IOException("Cannot open data connection.");
            }

            // create output stream
            OutputStream os = dataSoc.getOutputStream();
            if (factory.isZipMode()) {
                os = new DeflaterOutputStream(os);
            }
            return os;
        } catch (IOException ex) {
View Full Code Here

  public void
  connect()
    throws IOException
   
  {
    socket = new Socket( "127.0.0.1", MagnetURIHandler.getSingleton().getPort());
           
    String  get = "GET " + "/download/" + getURL().toString().substring( 7 ) + " HTTP/1.0" + NL + NL;
   
    socket.getOutputStream().write( get.getBytes());
   
View Full Code Here

  {
    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

        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

            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

                    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

    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

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.