Called when the socket connects
978158
def on_connect(self, connection):
        ""
        self._sock = connection._sock
        self._buffer = SocketBuffer(self._sock, self.socket_read_size)
        self.encoder = connection.encoder
1241424
function connection(socket){
	this.socket = socket;
	if (!!this.options.encoding) socket.setEncoding(this.options.encoding);
	socket.on('data', this.emit.bind(this, 'data'));
	this.emit('connection', socket);
}
801821
def on_connecting(self, host_and_port):
        
        log.info("connecting %s %s (x %s)", host_and_port[0], host_and_port[1], self.connections)
        self.connections += 1
1086687
def _init_socket(self):
        ''''''
        try:
            self._connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self._connection.connect((self.host, self.port))
            self._connection.settimeout(self.timeout)
            self._connection_file = self._connection.makefile('b')
        except:
            self._connection = None
            self._connection_file = None
            raise
1146985
function Socket() {
  this.server = null;
  this.socks = [];
  this.settings = {};
  this.set('hwm', Infinity);
  this.set('identity', String(process.pid));
  this.retry = 0
  this.set('retry timeout', 100);
  this.set('retry max timeout', 5000);
  this.set('max retry', 100);
}
93367
function (options, onConnect) {
    var self = this;
    EventEmitter.call(this);

    this.options = options;

    // debugging
    this.debug_enabled = options.debug;
    this.handshook = false;

    // received data which could not be parsed into messages yet
    this.data = '';

    // determine correct call of net.connect
    var cb = function () {
        connected.call(self);
        onConnect.call(self);
    };

    if (options.path) {
        this.debug("Trying to establish connection to unix socket %s", options.path);
        this.client = net.connect(options.path, cb);
    } else {
        this.debug("Trying to establish connection to %s on port %s", options.host, options.port);
        this.client = net.connect(options.port, options.host, cb);
    }

    // when data is received
    this.client.on('data', function (data) {
        var obj = dezeusify.call(self, data.toString('utf8'));
        obj.forEach(function (item) {
            received.call(self, item);
        });
    });

    // when the connection is closed
    this.client.on('end', function () {
        disconnected.call(self);
    });

    this.client.on('error', function (err) {
        self.debug("Whoops, an error occurred: %s", err.message);
        throw new Error(util.format("A connection error occurred: %s", err.message));
    });

    // when a new listener is added to this object, we'll want to check if we should notify the server
    this.on('newListener', function (evt) {
        this.debug("A new event listener was added");
        if (evt.toUpperCase() === evt && !this.subscribedEvents.indexOf(evt) !== -1) {
            subscribeServerEvent.call(self, evt);
        }
    });

    this.subscribedEvents = [];
    this.waitingCallbacks = [];
}
787791
def on_connect(client):
    """"""
    client.nick(client.user.nick)
    client.userinfo(client.user.username, client.user.realname)
264864
def connect(self):
        """"""
        if not self.connected:
            self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self.socket.connect(self.address)
            self.connected = True
371193
public void onStateChange() {
        switch (dataChannel.state()) {
            case CONNECTING:
                break;

            case OPEN: {
                    if (null != callReference) {
                        RespokeCall call = callReference.get();
                        if (null != call) {
                            call.directConnectionDidOpen(this);
                        }
                    }

                new Handler(Looper.getMainLooper()).post(new Runnable() {
                    public void run() {
                        if (null != listenerReference) {
                            Listener listener = listenerReference.get();
                            if (null != listener) {
                                listener.onOpen(RespokeDirectConnection.this);
                            }
                        }
                    }
                });
                }
                break;

            case CLOSING:
                break;

            case CLOSED: {
                    if (null != callReference) {
                        RespokeCall call = callReference.get();
                        if (null != call) {
                            call.directConnectionDidClose(this);
                        }
                    }

                    new Handler(Looper.getMainLooper()).post(new Runnable() {
                        public void run() {
                            if (null != listenerReference) {
                                Listener listener = listenerReference.get();
                                if (null != listener) {
                                    listener.onClose(RespokeDirectConnection.this);
                                }
                            }
                        }
                    });
                }
                break;
        }
    }
1123492
def connect(self, *args):
        """"""

        self.log("Connect ", args, lvl=verbose)

        try:
            sock = args[0]
            ip = args[1]

            if sock not in self._sockets:
                self.log("New client connected:", ip, lvl=debug)
                clientuuid = str(uuid4())
                self._sockets[sock] = Socket(ip, clientuuid)
                # Key uuid is temporary, until signin, will then be replaced
                #  with account uuid

                self._clients[clientuuid] = Client(
                    sock=sock,
                    ip=ip,
                    clientuuid=clientuuid,
                )

                self.log("Client connected:", clientuuid, lvl=debug)
            else:
                self.log("Old IP reconnected!", lvl=warn)
                #     self.fireEvent(write(sock, "Another client is
                # connecting from your IP!"))
                #     self._sockets[sock] = (ip, uuid.uuid4())
        except Exception as e:
            self.log("Error during connect: ", e, type(e), lvl=critical)
1211962
def connect(self):
        
        self.con = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.con.connect((self.ip, self.port))

        log.debug('Connected with set-top box at %s:%s.',
                  self.ip, self.port)
903596
void connect(SocketAddress socketAddress, boolean useSSL) {
        ChannelFactory channelFactory = new NioClientSocketChannelFactory(
            Executors.newCachedThreadPool(),
            Executors.newCachedThreadPool());

        ChannelPipeline clientPipeline = NettyChannelPipeline.newPipeline(connection);
        SslHandler sslHandler = null;

        if (useSSL) {
            sslHandler = getClientSSLHandler();
            clientPipeline.addFirst("ssl", sslHandler);
        }

        bootstrap = new ClientBootstrap(channelFactory);
        bootstrap.setOption("tcpNoDelay", true);
        bootstrap.setPipeline(clientPipeline);

        /*
         * The connection future and the connection itself aren't perfectly
         * synchronized so we have to wait for both to acknowledge that the
         * connection has been made
         */
        final CountDownLatch connectedLatch = new CountDownLatch(1);
        ConnectionStateListener connectedListener = new ConnectionStateListener() {
            @Override
            public void onConnectionConnected() {
                connectedLatch.countDown();
            }

            @Override
            public void onConnectionClosing() {
            }

            @Override
            public void onConnectionClosed() {
            }
        };

        connection.addConnectionStateListener(connectedListener);

        try {
            /* Perform connection */
            ChannelFuture future = bootstrap.connect(socketAddress);

            log.debug("connecting");

            future.await();

            if (future.isSuccess()) {
                /* This await should be very brief */
                connectedLatch.await();

                log.debug("connected successfully");

                if (useSSL) {
                    doSSLHandshake(sslHandler);
                }

                connected = true;
            } else {
                log.debug("connection failed");
                throw new ConnectionException(future.getCause());
            }
        } catch (InterruptedException e) {
            throw new ConnectionException("Interrupted while connecting");
        } finally {
            connection.removeConnectionStateListener(connectedListener);
        }
    }
258248
function socketOnEnd() {
  const websocket = this[kWebSocket];

  websocket.readyState = WebSocket.CLOSING;
  websocket._receiver.end();
  this.end();
}
589084
function handleConnection(self, options) {
	if (TRACE)	console.log('Connected to ' + options.host + ':' + options.port)
    	//self.socket = socket;
	self.emit("connect");
}
400231
def add_socket(self, socket):
        
        if socket not in self._sockets:
            self._sockets.add(socket)
            socket.on_closed.connect(self.remove_socket)
270265
function() {
      io = io.listen(app);
      io.set("log level", 1);
      io.sockets.on("connection", function(socket) {
        connections += 1;
        console.log("   info  -".cyan, ("new connection. Connections: " + connections).yellow);

        socket.on("disconnect", function() {
          connections -= 1;
          console.log("   info  -".cyan, ("connection closed. Connections: " + connections).yellow);
        });

        socket.on("iframe-loaded", function(data) {
          urlData[data.id].counter--;
          console.log("   info  -".cyan, ("client sends event iframe-loaded").yellow, JSON.stringify(data));
        });
      });
    }
1018050
def connect(self):
        """"""
        self.socket = socket.create_connection(self.address, self.timeout)