Package java.net

Examples of java.net.ServerSocket


  /**
   * @param args
   */
  public static void main(String[] args) {
    ServerSocket ss = null;
    try {
      ss = new ServerSocket(8899);
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    while(true) {
      Socket socket = null;
      try {
        socket = ss.accept();
        System.out.println("接入....");
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
View Full Code Here


       controlOut = null;
    }
     public void start() throws IOException
     {
          ServerSocket serverSocket;
          InetAddress myAddress = InetAddress.getLocalHost();
          byte[] address = myAddress.getAddress();
          String portCommand = "PORT ";
          serverSocket = new ServerSocket(0, 1);
          // append each byte of our address (comma-separated)
          for (int i = 0; i < address.length; i++)
          {
             portCommand = portCommand + (address[i] & 0xFF) + ",";
          }
       // append our server socket's port as two comma-separated
       // hex bytes

          portCommand = portCommand +
             ((serverSocket.getLocalPort() >>> 8)
             & 0xFF) + "," + (serverSocket.getLocalPort() & 0xFF);
          // issue PORT command
          if (issueCommand(portCommand) == FTP_ERROR)
          {
             serverSocket.close();
             throw new IOException("PORT");
          }
          // issue RETRieve command
          if (issueCommand("RETR " + fileString) == FTP_ERROR)
          {
             serverSocket.close();
             throw new IOException("RETR");
          }
          dataSocket = serverSocket.accept();
          serverSocket.close();
    }
View Full Code Here

    /* Attempt to open Port */
    for (int i = 0; i < ports.size(); i++) {
      try {
        int port = ports.get(i);
        fPort = port;
        return new ServerSocket(fPort, 50, InetAddress.getByName(LOCALHOST));
      } catch (UnknownHostException e) {
        throw e;
      } catch (BindException e) {
        if (i == (ports.size() - 1))
          throw e;
View Full Code Here

     */
    public void start()
        throws IOException
    {
        // Create the server socket.
        m_serverSocket = new ServerSocket( m_port, 5, m_bindAddr );
       
        m_runner = new Thread( this, "WrapperActionServer_runner" );
        m_runner.setDaemon( true );
        m_runner.start();
    }
View Full Code Here

        Thread runner = m_runner;
        m_runnerStop = true;
        runner.interrupt();

        // Close the server socket so it stops blocking for new connections.
        ServerSocket serverSocket = m_serverSocket;
        if ( serverSocket != null )
        {
            try
            {
                serverSocket.close();
            }
            catch ( IOException e )
            {
                // Ignore.
            }
View Full Code Here

    /* Attempt to open Port */
    for (int i = 0; i < ports.size(); i++) {
      try {
        int port = ports.get(i);
        fPort = port;
        return new ServerSocket(fPort, 50, InetAddress.getByName(LOCALHOST));
      } catch (UnknownHostException e) {
        throw e;
      } catch (BindException e) {
        if (i == (ports.size() - 1))
          throw e;
View Full Code Here

    /* Attempt to open Port */
    for (int i = 0; i < ports.size(); i++) {
      try {
        int port = ports.get(i);
        fPort = port;
        return new ServerSocket(fPort, 50, InetAddress.getByName(LOCALHOST));
      } catch (UnknownHostException e) {
        throw e;
      } catch (BindException e) {
        if (i == (ports.size() - 1))
          throw e;
View Full Code Here

    ServerMonitor(){
        try{
            if(_port < 0)
                return;
            setDaemon(true);
            _socket = new ServerSocket(_port, 1, InetAddress.getLocalHost());
            if(_port == 0){
                _port = _socket.getLocalPort();
                System.out.println(_port);
            }
            if("jManageKey".equals(_key)){
View Full Code Here

        }
    }

    public static RemoteListener openRemoteListener(JabRef jabref) {
        try {
            ServerSocket socket = new ServerSocket(Globals.prefs.getInt("remoteServerPort"), 1,
                    InetAddress.getByAddress(new byte[] {127, 0, 0, 1}));
            RemoteListener listener = new RemoteListener(jabref, socket);
            return listener;
        } catch (IOException e) {
            if (!e.getMessage().startsWith("Address already in use"))
View Full Code Here

 
    selector = Selector.open();         //打开选择器
   
    ssChannel = ServerSocketChannel.open();
    ssChannel.configureBlocking(false);       //设定为非阻塞
    ServerSocket ss = ssChannel.socket();
    ss.bind(this.getConfigure().getAddress());
   
       
    ssChannel.register(selector, SelectionKey.OP_ACCEPT);
   
    this.startIoReadWriteMachines();
View Full Code Here

TOP

Related Classes of java.net.ServerSocket

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.