/*
@Override
public QSocket socket()
{
return _qSocket;
}
351304
@Override
  public void run()
  {
    boolean isValid = false;
      
    try {
      _socket.getChannel().configureBlocking(true);
      /*
      EndpointReaderWebSocket wsEndpointReader = _client.getEndpointReader();
      
      do {
        if (! wsEndpointReader.onRead()) {
          return;
        }
      } while (wsEndpointReader.isReadAvailable() && ! _client.isClosed());
      
      isValid = ! _client.isClosed();
      
      if (isValid) {
        registerKeepalive();
      }
      */
    } catch (Exception e) {
      e.printStackTrace();
      log.log(Level.WARNING, e.toString(), e);
    } finally {
      if (! isValid) {
        _client.close();
      }
    }
  }
406416
@Override
    public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException {
        final SSLSocketFactory factory = sslCtxt.getSocketFactory();
        final SSLSocket ss = (SSLSocket) factory.createSocket(address, port, localAddress, localPort);

        ss.setEnabledProtocols(protocols);

        return ss;
    }
547716
def make_socket():
    '''
    '''
    mreq = struct.pack("4sl", socket.inet_aton(MCAST_IP), socket.INADDR_ANY)
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    sock.bind(('', MCAST_PORT))
    sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
    sock.settimeout(0.2)
    return sock
620362
function() {
      var t = this, socket = t.get('socket');
      for (var event in t.socketEvents) {
        socket.removeListener(event, t.socketEvents[event]);
      }
      t.socketEvents = null;
      return t;
    }
506091
protected function createSocket()
    {
        $now = $this->getCurrentTime();
        if ($this->retryTime === null) {
            $attempt = true;
        } else {
            $attempt = ($now >= $this->retryTime);
        }

        if (!$attempt) {
            return;
        }

        $this->socket = $this->makeSocket();
        if ($this->socket !== false) {
            $this->retryTime = null;
            return;
        }

        if ($this->retryTime === null) {
            $this->retryPeriod = $this->retryStart;
        } else {
            $this->retryPeriod *= $this->retryFactor;
            if ($this->retryPeriod > $this->retryMax) {
                $this->retryPeriod = $this->retryMax;
            }
        }
        $this->retryTime = $now + $this->retryPeriod;
    }
1286262
public CheckedSocket getSocket(Object session)
        throws ConnectException, SocketException
    {
        return CheckedSocket.check(new LazySocket(mFactory, session));
    }
402537
public WebSocketAdapter getWebsocketAdapter(){
       return new WebSocketAdapter() {

            @Override
            public void onConnected(WebSocket websocket, Map<String, List<String>> headers) {
                count = 0;
                nextReconnectInterval = 0;

                if (onConnectedListener != null) {
                    onConnectedListener.onConnected();
                }

                if (tryReconnection) {
                    if (timer != null) {
                        timer.cancel();
                    }
                    timer = new Timer();
                    timer.scheduleAtFixedRate(getTask(), 0, pongCheckInterval);

                }
            }

            @Override
            public void onTextMessage(WebSocket websocket, String message) {
                parseTextMessage(message);
            }

            @Override
            public void onBinaryMessage(WebSocket websocket, byte[] binary) {
                try {
                    super.onBinaryMessage(websocket, binary);
                } catch (Exception e) {
                    e.printStackTrace();
                    if(onErrorListener != null) {
                        onErrorListener.onError(e);
                    }
                }

                ArrayList<Tick> tickerData = parseBinary(binary);

                if (onTickerArrivalListener != null) {
                    onTickerArrivalListener.onTicks(tickerData);
                }
            }

            @Override
            public void onPongFrame(WebSocket websocket, WebSocketFrame frame) {
                try {
                    super.onPongFrame(websocket, frame);
                    Date date = new Date();
                    lastPongAt = date.getTime();
                } catch (Exception e) {
                    e.printStackTrace();
                    if(onErrorListener != null) {
                        onErrorListener.onError(e);
                    }
                }
            }

            /**
             * On disconnection, return statement ensures that the thread ends.
             *
             * @param websocket
             * @param serverCloseFrame
             * @param clientCloseFrame
             * @param closedByServer
             * @throws Exception
             */
            @Override
            public void onDisconnected(WebSocket websocket, WebSocketFrame serverCloseFrame, WebSocketFrame clientCloseFrame, boolean closedByServer) {
                if (onDisconnectedListener != null) {
                    onDisconnectedListener.onDisconnected();
                }
                return;
            }

            @Override
            public void onError(WebSocket websocket, WebSocketException cause) {
                try {
                    super.onError(websocket, cause);
                } catch (Exception e) {
                    e.printStackTrace();
                    if(onErrorListener != null) {
                        onErrorListener.onError(e);
                    }
                }
            }

        };
    }
539115
public static CheckedSocket check(SocketFace socket)
        throws SocketException
    {
        if (socket instanceof CheckedSocket) {
            return (CheckedSocket)socket;
        }
        else {
            return new CheckedSocket(socket);
        }
    }
1023590
function Socket(node) {

        // ## Public properties

        /**
         * ### Socket.buffer
         *
         * Buffer of queued incoming messages
         *
         * @api private
         */
        this.buffer = [];

        /**
         * ### Socket.outBuffer
         *
         * Buffer of queued outgoing messages
         *
         * TODO: implement!
         *
         * @api private
         */
        // this.outBuffer = [];

        /**
         * ### Socket.session
         *
         * The session id shared with the server
         *
         * This property is initialized only when a game starts
         *
         */
        this.session = null;

        /**
         * ### Socket.userOptions
         *
         * Contains the options that will be passed to the `connect` method
         *
         * The property is set by `node.setup.socket`.
         * Passing options to the `connect` method will overwrite this property.
         *
         * @see node.setup
         * @see Socket.connect
         */
        this.userOptions = {};

        /**
         * ### Socket.socket
         *
         * The actual socket object (e.g. SocketDirect, or SocketIo)
         */
        this.socket = null;

        /**
         * ### Socket.connected
         *
         * Socket connection established
         *
         * For realiably checking whether the connection is established
         * use `Socket.isConnected()`.
         *
         * @see Socket.connecting
         * @see Socket.isConnected
         * @see Socket.onConnect
         * @see Socket.onDisconnect
         */
        this.connected = false;

        /**
         * ### Socket.connecting
         *
         * Socket connection being established
         *
         * TODO see whether we should merge connected / connecting
         * in one variable with socket states.
         *
         * @see Socket.connected
         * @see Socket.isConnected
         * @see Socket.onConnect
         * @see Socket.onDisconnect
         */
        this.connecting = false;


         /**
         * ### Socket.reconnecting
         *
         * Flags that a reconnection is in progress
         *
         * This is useful when `Socket.reconnect()` triggers a disconnection
         *
         * @see Socket.reconnect
         */
        this.reconnecting = false;

         /**
         * ### Socket.connectingTimeout
         *
         * Timeout to cancel the connecting procedure
         *
         * @see Socket.connecting
         * @see Socket.connect
         */
        this.connectingTimeout = null;

         /**
         * ### Socket.connectingTimeoutMs
         *
         * Number of milliseconds for the connecting timeout
         *
         * Default: 10000 (10 seconds)
         *
         * @see Socket.connecting
         * @see Socket.connect
         */
        this.connectingTimeoutMs = 10000;

        /**
         * ### Socket.url
         *
         * The full url to which the socket is connected
         *
         * This is set when a new connection attempt is started.
         *
         * It might not be meaningful for all types of sockets. For example,
         * in case of SocketDirect, it is not an real url.
         *
         * @see Socket.connect
         */
        this.url = null;

        /**
         * ### Socket.channelName
         *
         * The name of the channel to which the socket is connected
         *
         * This is set upon a successful connection.
         *
         * @see Socket.startSession
         */
        this.channelName = null;

        /**
         * ### Socket.type
         *
         * The type of socket used
         */
        this.type = null;

        /**
         * ### Socket.emitOutMsg
         *
         * If TRUE, outgoing messages will be emitted upon sending
         *
         * This allows, for example, to modify all outgoing messages.
         */
        this.emitOutMsg = false;

        /**
         * ### Socket.antiSpoofing
         *
         * If TRUE, sid is added to each message
         *
         * This setting is sent over by server.
         */
        this.antiSpoofing = null;

        // Experimental Journal.
        // TODO: check if we need it.
        this.journalOn = false;

        // Experimental
        this.journal = new parent.NDDB({
            update: {
                indexes: true
            }
        });
        this.journal.comparator('stage', function(o1, o2) {
            return parent.GameStage.compare(o1.stage, o2.stage);
        });

        if (!this.journal.player) {
            this.journal.hash('to', function(gb) {
                return gb.to;
            });
        }
        if (!this.journal.stage) {
            this.journal.hash('stage', function(gb) {
                if (gb.stage) {
                    return parent.GameStage.toHash(gb.stage, 'S.s.r');
                }
            });
        }
        // End Experimental Code.

        /**
         * ### Socket.node
         *
         * Reference to the node object.
         */
        this.node = node;
    }
433600
public Socket getSocket(String host, int port, boolean useSecureSocket, SecurityDomain securityDomain) throws Exception {
		return getSocket(host,port,useSecureSocket,securityDomain,null);
	}
854591
protected SocketBox openSocket() throws Exception {
        SocketBox sBox = new SimpleSocketBox();

        SocketFactory factory = SocketFactory.getDefault();
        Socket mySocket = factory.createSocket(this.hostPort.getHost(),
                                               this.hostPort.getPort());
        sBox.setSocket(mySocket);

        return sBox;
    }
340339
protected function configureSocket()
    {
        $class = $this->options['socket_class'];
        $options = $this->options['socket_options'];
        $this->socket = new $class($this->uri, $options);
    }
443910
function bindReqSocket(req, socket) {
  //gReqCount++;
  req.onSocket(socket);
  socket._reqCount++;
  socket._used = true;
  timers.unenroll(socket._kpTimer);
}
277147
public function getSocket()
    {
        if (is_null($this->resource)) {
            $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
            if ($socket === false) {
                throw new RequestLogException('Unable to open TCP socket: '.socket_strerror(socket_last_error()));
            }
            $success = socket_connect($socket, $this->getOption(self::OPTION_HOST), $this->getOption(self::OPTION_PORT));
            if ($success === false) {
                throw new RequestLogException('Unable to connect to host: '.socket_strerror(socket_last_error()));
            }
            $this->resource = $socket;
        }
        return $this->resource;
    }
1177961
public void setSocket(Socket socket) {
	    if (socket != null)
	    {
	      m_remoteAddress = socket.getInetAddress();
	      this.port = socket.getPort();
	      m_controlThread = new DebugControlConnectionThread(socket, this);
	      m_controlThread.start();
	      executeStartupCommands();
	      m_controlThread.sendMessage("getsettings");

	      m_controlThread.sendMessage("[out-network");
	      //m_controlThread.sendMessage("[out-network-true");
	      String networkTracePortStr = m_controlThread.getMessage();
	      int networkTracePort = Integer.parseInt(networkTracePortStr);
	      if (LOG.isDebugEnabled()) LOG.debug("Received network trace port [" + networkTracePort + "]");
	      
	      try
	      {
	        INetworkOutputConfig config = new INetworkOutputConfig()
	        {
		          @Override
		          public boolean isNetOutputEnabled()
		          {
		            return m_settingsData.netOutEnabled;
		          }

				@Override
				public boolean isGzipEnabled() {
					return m_settingsData.gzipEnabled;
				}
	        };
	        	        
	        m_networkTraceThread2 = new NetworkDataReceiverThread2(
	        							m_remoteAddress,
	        							networkTracePort, 
	        							config
	        							);
	        m_networkTraceThread2.start();
		      setConnectState(ConnectState.CONNECTED);
		      setConnectionStatusMsg(DefaultFactory.getFactory().getMessages().getConnected());
	        
	      } catch (IOException ex)
	      {
	    	  m_traceEvents.add(
	    			  	TraceFactory.createExceptionTraceEvent(
	    			  			org.headlessintrace.rcp.ClientStrings.TRACE_CREATION_ERROR, 
	    			  			ex, 
	    			  			m_remoteAddress, 
	    			  			networkTracePortStr));
	      }
	      
	    } else
	    {
	      setConnectState(ConnectState.DISCONNECTED_ERR);
	    }
	}
298802
@Override
	public Socket makeObject(InetSocketAddress address) throws Exception {
		Socket socket = new Socket(address.getHostName(), address.getPort());
		socket.setKeepAlive(true);
		return socket;
	}
785368
@Override
	public DatagramSocket makeObject(SocketAddress socketAddress) throws Exception {
		DatagramSocket datagramSocket = new DatagramSocket();
		datagramSocket.connect(socketAddress);
		return datagramSocket;
	}