Create and bind the ZAP socket
332758
def start(self):
        """"""
        self.zap_socket = self.context.socket(zmq.REP)
        self.zap_socket.linger = 1
        zapLoc = 'inproc://zeromq.zap.{}'.format(MultiZapAuthenticator.count)
        self.zap_socket.bind(zapLoc)
        self.log.debug('Starting ZAP at {}'.format(zapLoc))
676809
def bind(self, family, type, proto=0):
    """"""
    self.socket = sockets.Socket(family, type, proto)
    self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    self.socket.setblocking(0)
    #~ self.socket.setsockopt(socket.SOL_SOCKET, socket.TCP_NODELAY, 1)
    self.socket.bind(self.bind_addr)
820091
public static Socket fork(ZContext ctx, IAttachedRunnable runnable, Object... args)
    {
        Socket pipe = ctx.createSocket(SocketType.PAIR);

        if (pipe != null) {
            pipe.bind(String.format("inproc://zctx-pipe-%d", pipe.hashCode()));
        }
        else {
            return null;
        }

        //  Connect child pipe to our pipe
        ZContext ccontext = ZContext.shadow(ctx);
        Socket cpipe = ccontext.createSocket(SocketType.PAIR);
        if (cpipe == null) {
            return null;
        }
        cpipe.connect(String.format("inproc://zctx-pipe-%d", pipe.hashCode()));

        //  Prepare child thread
        Thread shim = new ShimThread(ccontext, runnable, args, cpipe);
        shim.start();

        return pipe;
    }
905348
def bind(self, family, type, proto=0):
        """"""
        sock = self.prepare_socket(
            self.bind_addr,
            family, type, proto,
            self.nodelay, self.ssl_adapter,
        )
        sock = self.socket = self.bind_socket(sock, self.bind_addr)
        self.bind_addr = self.resolve_real_bind_addr(sock)
        return sock
948011
def prepare_socket(bind_addr, family, type, proto, nodelay, ssl_adapter):
        """"""
        sock = socket.socket(family, type, proto)
        prevent_socket_inheritance(sock)

        host, port = bind_addr[:2]
        IS_EPHEMERAL_PORT = port == 0

        if not (IS_WINDOWS or IS_EPHEMERAL_PORT):
            """Enable SO_REUSEADDR for the current socket.

            Skip for Windows (has different semantics)
            or ephemeral ports (can steal ports from others).

            Refs:
            * https://msdn.microsoft.com/en-us/library/ms740621(v=vs.85).aspx
            * https://github.com/cherrypy/cheroot/issues/114
            * https://gavv.github.io/blog/ephemeral-port-reuse/
            """
            sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        if nodelay and not isinstance(bind_addr, str):
            sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)

        if ssl_adapter is not None:
            sock = ssl_adapter.bind(sock)

        # If listening on the IPV6 any address ('::' = IN6ADDR_ANY),
        # activate dual-stack. See
        # https://github.com/cherrypy/cherrypy/issues/871.
        listening_ipv6 = (
            hasattr(socket, 'AF_INET6')
            and family == socket.AF_INET6
            and host in ('::', '::0', '::0.0.0.0')
        )
        if listening_ipv6:
            try:
                sock.setsockopt(
                    socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0,
                )
            except (AttributeError, socket.error):
                # Apparently, the socket option is not available in
                # this machine's TCP stack
                pass

        return sock
1054191
def initialize_socket(self):
        """"""
        try:
            _LOGGER.debug("Trying to open socket.")
            self._socket = socket.socket(
                socket.AF_INET,     # IPv4
                socket.SOCK_DGRAM   # UDP
            )
            self._socket.bind(('', self._udp_port))
        except socket.error as err:
            raise err
        else:
            _LOGGER.debug("Socket open.")
            socket_thread = threading.Thread(
                name="SocketThread", target=socket_worker,
                args=(self._socket, self.messages,))
            socket_thread.setDaemon(True)
            socket_thread.start()
895212
def connect(self):
        """"""
        distributed_logger.info('Connecting registry proxy to ZMQ socket %s', self.socket_addr)
        self.zmq_context = zmq.Context()
        sock = self.zmq_context.socket(zmq.PUB)
        sock.set_hwm(0)
        sock.setsockopt(zmq.LINGER, 0)
        sock.connect(self.socket_addr)
        distributed_logger.info('Connected registry proxy to ZMQ socket %s', self.socket_addr)

        def _reset_socket(values):
            for value in values:
                try:
                    _reset_socket(value.values())
                except AttributeError:
                    value.socket = sock

        distributed_logger.debug('Resetting socket on metrics proxies')
        _reset_socket(self.stats.values())
        self.socket = sock
        distributed_logger.debug('Reset socket on metrics proxies')
713809
void createImpl() throws SocketException {
        if (impl == null)
            setImpl();
        try {
            impl.create(true);
            created = true;
        } catch (IOException e) {
            throw new SocketException(e.getMessage());
        }
    }
592103
def __bind(self):
        '''
        
        '''
        # using ZMQIOLoop since we *might* need zmq in there
        install_zmq()
        self.io_loop = ZMQDefaultLoop()
        self.io_loop.make_current()
        for req_channel in self.req_channels:
            req_channel.post_fork(self._handle_payload, io_loop=self.io_loop)  # TODO: cleaner? Maybe lazily?
        try:
            self.io_loop.start()
        except (KeyboardInterrupt, SystemExit):
            # Tornado knows what to do
            pass
1109521
private void doBind() throws Exception {
        LOG.debug("Creating listener socket");
        try {
            m_selector = Selector.open();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        ServerSocketChannel listenerSocket = ServerSocketChannel.open();
        InetSocketAddress inetsockaddr;
        if ((m_internalInterface == null) || (m_internalInterface.length() == 0)) {
            inetsockaddr = new InetSocketAddress(m_internalPort);
        }
        else {
            inetsockaddr = new InetSocketAddress(m_internalInterface, m_internalPort);
        }
        try {
            hostLog.info("Attempting to bind to internal ip " + inetsockaddr);
            listenerSocket.socket().bind(inetsockaddr);
            listenerSocket.configureBlocking(false);
            m_listenerSockets.add(listenerSocket);
        } catch (Exception e) {
            /*
             * If we bound to the leader address, the internal interface address  might not
             * bind if it is all interfaces
             */
            if (m_listenerSockets.isEmpty()) {
                LOG.fatal("Failed to bind to " + inetsockaddr);
                CoreUtils.printPortsInUse(hostLog);
                throw e;
            }
        }

        for (ServerSocketChannel ssc : m_listenerSockets) {
            ssc.register(m_selector, SelectionKey.OP_ACCEPT);
        }

        if (LOG.isDebugEnabled()) {
            LOG.debug("Non-Primary Listening on:" + inetsockaddr.toString());
        }
    }
748432
function bindSocket(io, indicator) {
    Object.keys(indicator.watch).forEach((key) => {
        let eventName = indicator.watch[key];
        indicator.on(eventName, (msg) => io.emit(eventName, msg));
    });
}
135092
def prepare(self):
        
        self._interrupt = None

        if self.software is None:
            self.software = '%s Server' % self.version

        # Select the appropriate socket
        self.socket = None
        msg = 'No socket could be created'
        if os.getenv('LISTEN_PID', None):
            # systemd socket activation
            self.socket = socket.fromfd(3, socket.AF_INET, socket.SOCK_STREAM)
        elif isinstance(self.bind_addr, six.string_types):
            # AF_UNIX socket
            try:
                self.bind_unix_socket(self.bind_addr)
            except socket.error as serr:
                msg = '%s -- (%s: %s)' % (msg, self.bind_addr, serr)
                six.raise_from(socket.error(msg), serr)
        else:
            # AF_INET or AF_INET6 socket
            # Get the correct address family for our host (allows IPv6
            # addresses)
            host, port = self.bind_addr
            try:
                info = socket.getaddrinfo(
                    host, port, socket.AF_UNSPEC,
                    socket.SOCK_STREAM, 0, socket.AI_PASSIVE,
                )
            except socket.gaierror:
                sock_type = socket.AF_INET
                bind_addr = self.bind_addr

                if ':' in host:
                    sock_type = socket.AF_INET6
                    bind_addr = bind_addr + (0, 0)

                info = [(sock_type, socket.SOCK_STREAM, 0, '', bind_addr)]

            for res in info:
                af, socktype, proto, canonname, sa = res
                try:
                    self.bind(af, socktype, proto)
                    break
                except socket.error as serr:
                    msg = '%s -- (%s: %s)' % (msg, sa, serr)
                    if self.socket:
                        self.socket.close()
                    self.socket = None

        if not self.socket:
            raise socket.error(msg)

        # Timeout so KeyboardInterrupt can be caught on Win32
        self.socket.settimeout(1)
        self.socket.listen(self.request_queue_size)

        # Create worker threads
        self.requests.start()

        self.ready = True
        self._start_time = time.time()
625282
protected function createWorkerJobSocket()
    {
        $workerJobContext = new \ZMQContext;
        $this->workerJobSocket = $workerJobContext->getSocket(\ZMQ::SOCKET_PUB);
        $this->workerJobSocket->bind($this->config['sockets']['worker_job']);
    }
1235409
def bind(endpoint)
      rc = ffi_delegate.bind("%s", :string, endpoint)
      raise_zmq_err("unable to bind to %p" % endpoint) if rc == -1
      @last_tcp_port = rc if rc > 0
    end
841890
private void bindEndpoints(ZMQ.Socket socket, Iterable<String> ipAddresses, Map<String, ZMQ.Socket> endpoints, SocketType socketType) {
        xlogger.entry(ipAddresses, endpoints, socketType);


        for (String ipAddress : ipAddresses) {
            final StringBuilder endpoint = new StringBuilder("tcp://").append(ipAddress).append(":*");


            int port = socket.bind(endpoint.toString());

            //replace * with actual port
            endpoint.deleteCharAt(endpoint.length() - 1).append(port);
            endpoints.put(endpoint.toString(), socket);
            logger.debug("bind ZMQ socket {} for {}", endpoint.toString(), socketType);
        }

        xlogger.exit();
    }
1051962
def initialize(self, timeouts):
        

        # Bind or connect to address
        if self.bind is True:
            self.socket.bind(self.address)
        else:
            self.socket.connect(self.address)

        # Set send and recv timeouts
        self._set_timeouts(timeouts)
350829
function ZNPClient(config) {
  this._devices = {};

  this.config = config;

  if (!config || !config.panId) {
    throw new Error('You must set "panId" on ZNPClient config');
  }

  this.comms = new ZNPSerial();

  // Device state notifications
  this.comms.on('command:ZDO_STATE_CHANGE_IND', this._handleStateChange.bind(this));

  // Device announcements
  this.comms.on('command:ZDO_END_DEVICE_ANNCE_IND', this._handleDeviceAnnounce.bind(this));

  // Device endpoint responses
  this.comms.on('command:ZDO_MATCH_DESC_RSP', this._handleDeviceMatchDescriptionResponse.bind(this));
  this.comms.on('command:ZDO_ACTIVE_EP_RSP', this._handleDeviceMatchDescriptionResponse.bind(this));

  // Endpoint description responses
  this.comms.on('command:ZDO_SIMPLE_DESC_RSP', this._handleEndpointSimpleDescriptorResponse.bind(this));

  // Application framework (ZCL) messages
  this.comms.on('command:AF_INCOMING_MSG', this._handleAFIncomingMessage.bind(this));
}