Binds channel to the first available port.

@throws SocketException
333779
public void bind(boolean isLocal) throws IOException, SocketException {
		try {
			rtpChannel = udpManager.open(rtpHandler);

			// if control enabled open rtcp channel as well
			if (channelsManager.getIsControlEnabled()) {
				rtcpChannel = udpManager.open(new RTCPHandler());
			}
		} catch (IOException e) {
			throw new SocketException(e.getMessage());
		}

		// bind data channel
		if (!isLocal) {
			this.rxBuffer.setInUse(true);
			udpManager.bind(rtpChannel, PORT_ANY);
		} else {
			this.rxBuffer.setInUse(false);
			udpManager.bindLocal(rtpChannel, PORT_ANY);
		}
		this.rtpChannelBound = true;

		// if control enabled open rtcp channel as well
		if (channelsManager.getIsControlEnabled()) {
			if (!isLocal)
				udpManager.bind(rtcpChannel, rtpChannel.socket()
						.getLocalPort() + 1);
			else
				udpManager.bindLocal(rtcpChannel, rtpChannel.socket()
						.getLocalPort() + 1);
		}
	}
926853
def server_bind(self):
        

        if self.allow_reuse_address:
            self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.socket.bind(self.server_address)
844661
private void initializeSocketOption() {
    try {

      socket.setTcpNoDelay(options.tcpNoDelay);

      if (options.tcpKeepAlive) {
        socket.setKeepAlive(true);
      }
      if (options.tcpRcvBuf != null) {
        socket.setReceiveBufferSize(options.tcpRcvBuf);
      }
      if (options.tcpSndBuf != null) {
        socket.setSendBufferSize(options.tcpSndBuf);
      }
      if (options.tcpAbortiveClose) {
        socket.setSoLinger(true, 0);
      }
    } catch (Exception e) {
      logger.debug("Failed to set socket option", e);
    }
  }
65727
@SuppressWarnings("unchecked") // Channel Framework implements state map...
   public void connect(Object address) throws Exception
   {
      if (tc.isEntryEnabled()) SibTr.entry(this, tc, "connect", address);

      final JFapAddress jfapAddress = (JFapAddress) address;
      if ((jfapAddress != null) && (jfapAddress.getAttachType() == Conversation.CLIENT))
      {
         vc.getStateMap().put(OutboundProtocol.PROTOCOL, "BUS_CLIENT");
      }
      else
         vc.getStateMap().put(OutboundProtocol.PROTOCOL, "BUS_TO_BUS");
      
      super.connect(address);

      if (tc.isEntryEnabled()) SibTr.exit(this, tc, "connect");
   }
813275
public void bind(ServerSocketBar ss)
    throws IOException
  {
    Objects.requireNonNull(ss);

    _isBind.set(true);

    if (_protocol == null)
      throw new IllegalStateException(L.l("'{0}' must have a configured protocol before starting.", this));

    if (_throttle == null)
      _throttle = new ThrottleSocket();

    _serverSocket = ss;

    String scheme = _protocol.name();

    if (_address != null)
      log.info(scheme + " listening to " + _address + ":" + _port);
    else
      log.info(scheme + " listening to *:" + _port);

    if (_sslFactory != null) {
      try {
        _serverSocket = _sslFactory.bind(_serverSocket);
      } catch (RuntimeException e) {
        throw e;
      } catch (IOException e) {
        throw e;
      } catch (Exception e) {
        throw new IOException(e);
      }
    }
  }
558972
public synchronized void prepareSocket() throws IOException {
        if (!prepared) {
            final long fd = getFileDescriptor();
            if (fd == INVALID_SOCKET) {
                throw new AsyncException(AsyncProperties.aio_handle_unavailable);
            }

            channelIdentifier = provider.prepare2(fd, asyncChannelGroup.getCompletionPort());

            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "prepareSocket - socket prepared, fd = " + fd
                             + " channel id: " + channelIdentifier + " "
                             + ", local: " + channel.socket().getLocalSocketAddress()
                             + ", remote: " + channel.socket().getRemoteSocketAddress());
            }
            long callid = 0; // init to zero, reset when IO requested

            readIOCB = (CompletionKey) AsyncLibrary.completionKeyPool.get();
            if (readIOCB != null) {
                // initialize the IOCB from the pool
                readIOCB.initializePoolEntry(channelIdentifier, callid);

                writeIOCB = (CompletionKey) AsyncLibrary.completionKeyPool.get();
                if (writeIOCB != null) {
                    // initialize the IOCB from the pool
                    writeIOCB.initializePoolEntry(channelIdentifier, callid);
                } else {
                    writeIOCB = new CompletionKey(channelIdentifier, callid, defaultBufferCount);
                }
            } else {
                readIOCB = new CompletionKey(channelIdentifier, callid, defaultBufferCount);
                writeIOCB = new CompletionKey(channelIdentifier, callid, defaultBufferCount);
            }

            provider.initializeIOCB(readIOCB);
            provider.initializeIOCB(writeIOCB);
            prepared = true;
        }
    }
442596
private void doSocketConnect(InetSocketAddress addr) throws IOException{
        SocketChannel sock = createSock();
        registerAndConnect(sock, addr);
    }
406399
@Skip
    @Override
    public void bind(ChannelHandlerContext ctx, SocketAddress localAddress,
                     ChannelPromise promise) throws Exception {
        ctx.bind(localAddress, promise);
    }
1366937
protected final void configureSocketChannel(SocketChannel sc) throws IOException {
    sc.socket().setSoTimeout(this.soTimeout);
    sc.configureBlocking(false);
    if (this.socketOptions.get(StandardSocketOption.SO_REUSEADDR) != null) {
      sc.socket().setReuseAddress(StandardSocketOption.SO_REUSEADDR.type()
          .cast(this.socketOptions.get(StandardSocketOption.SO_REUSEADDR)));
    }
    if (this.socketOptions.get(StandardSocketOption.SO_SNDBUF) != null) {
      sc.socket().setSendBufferSize(StandardSocketOption.SO_SNDBUF.type()
          .cast(this.socketOptions.get(StandardSocketOption.SO_SNDBUF)));
    }
    if (this.socketOptions.get(StandardSocketOption.SO_KEEPALIVE) != null) {
      sc.socket().setKeepAlive(StandardSocketOption.SO_KEEPALIVE.type()
          .cast(this.socketOptions.get(StandardSocketOption.SO_KEEPALIVE)));
    }
    if (this.socketOptions.get(StandardSocketOption.SO_LINGER) != null) {
      sc.socket().setSoLinger(this.soLingerOn, StandardSocketOption.SO_LINGER.type()
          .cast(this.socketOptions.get(StandardSocketOption.SO_LINGER)));
    }
    if (this.socketOptions.get(StandardSocketOption.SO_RCVBUF) != null) {
      sc.socket().setReceiveBufferSize(StandardSocketOption.SO_RCVBUF.type()
          .cast(this.socketOptions.get(StandardSocketOption.SO_RCVBUF)));

    }
    if (this.socketOptions.get(StandardSocketOption.TCP_NODELAY) != null) {
      sc.socket().setTcpNoDelay(StandardSocketOption.TCP_NODELAY.type()
          .cast(this.socketOptions.get(StandardSocketOption.TCP_NODELAY)));
    }
  }
444275
private void attemptSocketBind(ServerSocket serverSocket, SocketAddress address, boolean reuseflag, int backlog) throws IOException {
        serverSocket.setReuseAddress(reuseflag);
        serverSocket.bind(address, backlog);
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "ServerSocket bind worked, reuse=" + serverSocket.getReuseAddress());
        }
    }
76203
public void bindAndStart(int port) throws Exception {
        server = new NioServer(new StreamConnectionFactory() {
            @Override
            public ProtobufConnection<Protos.TwoWayChannelMessage> getNewConnection(InetAddress inetAddress, int port) {
                return new ServerHandler(new InetSocketAddress(inetAddress, port), timeoutSeconds).socketProtobufHandler;
            }
        }, new InetSocketAddress(port));
        server.startAsync();
        server.awaitRunning();
    }
1234468
private void prepSocketChannel(SocketChannel sc) {
        try {
            sc.socket().setSendBufferSize(1024 * 1024 * 2);
            sc.socket().setReceiveBufferSize(1024 * 1024 * 2);
        } catch (SocketException e) {
            e.printStackTrace();
        }
    }
657809
def bind_channel(self, channel, callback):
        """"""

        # Remove the following list when deprecation time expires
        if channel in self.CHANNELS:
            warning = (
                "The event name '{}' will soon be deprecated. Use "
                "the real event name '{}' instead."
            ).format(channel, self.CHANNELS[channel])

            self.handle_error(warning)
            channel = self.CHANNELS[channel]
        # -------------------------------------------------------

        if channel == self.EVENT_NAME_ERROR:
            self.error_callback = callback
        elif channel == self.EVENT_NAME_RESULTS:
            self.socketIO.on(channel, partial(self.unpack_results, callback))
        else:
            self.socketIO.on(channel, callback)
151249
@Override
    @Trivial
    public void start() throws ChannelException {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
            Tr.event(tc, "Start channel: " + this);
        }
        stop0Called = false;
    }
504224
public function bind()
    {

        $err = $errno = 0;

        $this->FLASH_POLICY_FILE = str_replace('to-ports="*', 'to-ports="' . $this->uri->getPort() ?: 80, $this->FLASH_POLICY_FILE);

        $serverSocket = stream_socket_server($this->uri->toString(), $errno, $err, STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, $this->_context);

        $this->_logger->notice(sprintf("phpws listening on %s", $this->uri->toString()));

        if ($serverSocket == false) {
            $this->_logger->err("Error: $err");
            return;
        }

        $timeOut = & $this->purgeUserTimeOut;
        $sockets = $this->_streams;
        $that = $this;
        $logger = $this->_logger;

        $this->loop->addReadStream($serverSocket, function ($serverSocket) use ($that, $logger, $sockets) {
            try
            {
                $newSocket = stream_socket_accept($serverSocket);
            } catch (\ErrorException $e) {
                $newSocket = false;
            }

            if (false === $newSocket) {
                return;
            }

            stream_set_blocking($newSocket, 0);
            $client = new WebSocketConnection($newSocket, $that->loop, $logger);
            $sockets->attach($client);

            $client->on("handshake", function(Handshake $request) use($that, $client){
                $that->emit("handshake",array($client->getTransport(), $request));
            });

            $client->on("connect", function () use ($that, $client, $logger) {
                $con = $client->getTransport();
                $that->getConnections()->attach($con);
                $that->emit("connect", array("client" => $con));
            });

            $client->on("message", function ($message) use ($that, $client, $logger) {
                $connection = $client->getTransport();
                $that->emit("message", array("client" => $connection, "message" => $message));
            });

            $client->on("close", function () use ($that, $client, $logger, &$sockets) {
                $sockets->detach($client);
                $connection = $client->getTransport();

                if($connection){
                    $that->getConnections()->detach($connection);
                    $that->emit("disconnect", array("client" => $connection));
                }
            });

            $client->on("flashXmlRequest", function () use ($that, $client) {
                $client->getTransport()->sendString($that->FLASH_POLICY_FILE);
                $client->close();
            });
        });

        $this->loop->addPeriodicTimer(5, function () use ($timeOut, $sockets, $that) {

            # Lets send some pings
            foreach($that->getConnections() as $c){
                if($c instanceof WebSocketTransportHybi)
                    $c->sendFrame(WebSocketFrame::create(WebSocketOpcode::PingFrame));
            }

            $currentTime = time();
            if ($timeOut == null)
                return;

            foreach ($sockets as $s) {
                if ($currentTime - $s->getLastChanged() > $timeOut) {
                    $s->close();
                }
            }
        });
    }
1182931
public Future<Void> start(final int port) {
        final ChannelFuture channelFuture = this.bootstrap.bind(port);
        this.allChannels.add(channelFuture.channel());

        return channelFuture;
    }
825141
public void setChannelData(ChannelData data) throws ChannelException {
        this.channelData = data;
        setValues(data.getPropertyBag());
        if (tc.isDebugEnabled())
            outputConfigToTrace();
    }