Package java.net

Examples of java.net.ServerSocket.bind()


        // Bind the server socket to the local host and port
        InetAddress host = InetAddress.getLocalHost();
        InetSocketAddress sockAddr = new InetSocketAddress(host, PORT);
        ServerSocket socket = channel.socket();
        //socket.setReuseAddress(true);
        socket.bind(sockAddr);

        // Register accepts on the server socket with the selector. This
        // step tells the selector that the socket wants to be put on the
        // ready list when accept operations occur.
        Selector selector = Selector.open();
View Full Code Here


     */
    public InetSocketAddress setup() throws IOException {
        ServerSocket servSocket = serverChannel.socket();
        servSocket.setReuseAddress(true);
        InetSocketAddress sockaddr = NetUtils.getAnyLocalInetSocketAddress();
        servSocket.bind(sockaddr);
        return sockaddr;
    }

    public void setup(int port) throws IOException {
        ServerSocket servSocket = serverChannel.socket();
View Full Code Here

    public void setup(int port) throws IOException {
        ServerSocket servSocket = serverChannel.socket();
        servSocket.setReuseAddress(true);
        InetAddress addr = NetUtils.getLocalHost(false);
        InetSocketAddress sockaddr = new InetSocketAddress(addr, port);
        servSocket.bind(sockaddr);
    }

    public void run() {
        final ExecutorService execPool = this.execPool;
        final TransferRequestListener handler = this.handler;
View Full Code Here

     
      ServerSocket ss  = ssc.socket();
     
      ss.setReuseAddress(true);

      ss.bindnew InetSocketAddress( InetAddress.getByName("127.0.0.1"), port), 128 );
     
      if ( port == 0 ){
       
        port  = ss.getLocalPort();
      }
View Full Code Here

    }

    ServerSocket serverSocket = new ServerSocket();
    // http://java.sun.com/j2se/1.5.0/docs/api/java/net/ServerSocket.html#setReuseAddress(boolean)
    serverSocket.setReuseAddress(true);
    serverSocket.bind(isa, this.backlog);

    if (this.port == 0)
    {
      this.port = serverSocket.getLocalPort();
    }
View Full Code Here

    public NioSocketServer(boolean useNIO) throws IOException {
        if (useNIO) {
            ServerSocketChannel ssc = ServerSocketChannel.open();
            ssc.configureBlocking(false);
            ServerSocket ss = ssc.socket();
            ss.bind(new InetSocketAddress(LISTEN_PORT));
           
            this.selector = Selector.open();
            ssc.register(this.selector, SelectionKey.OP_ACCEPT);
        } else {
            this.serverSocket = new ServerSocket(LISTEN_PORT);
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

      serverSocket.setReuseAddress( true );
      final InetAddress localAddress = InetAddress.getLocalHost();
      final Random random = new Random();
      final int port = Math.abs( random.nextInt() % 5000 ) + 1024;
      final InetSocketAddress address = new InetSocketAddress( localAddress, port );
      serverSocket.bind( address );
      while ( !serverSocket.isBound() )
      {
         System.out.print( "." );
         Thread.yield();
      }
View Full Code Here

 
  protected ServerSocket newServerSocket() throws IOException
  {
    ServerSocket ss = new ServerSocket();
    if (getHost() == null)
      ss.bind(new InetSocketAddress(getPort()));
    else
      ss.bind(new InetSocketAddress(getHost(), getPort()));
    return ss;
  }
 
View Full Code Here

  {
    ServerSocket ss = new ServerSocket();
    if (getHost() == null)
      ss.bind(new InetSocketAddress(getPort()));
    else
      ss.bind(new InetSocketAddress(getHost(), getPort()));
    return ss;
  }
 
  public void accept(int acceptorID) throws IOException, InterruptedException
  {
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.