public static INodeSharpClient Create(ISocketClient socket, string nodeExePath, string nodeJsPath) { var process = SpawnProcess(nodeExePath, nodeJsPath); socket.Connect(); return(new NodeSharpClient { Socket = socket, NodeProcess = process }); }
// Use this for initialization private IEnumerator Start() { _client = FlexiSocket.Create("localhost", 1366, Protocols.BodyLengthPrefix); _client.Connected += OnConnected; _client.Disconnected += OnDisconnected; _client.Received += OnReceived; _client.Sent += OnSent; yield return(new WaitForSeconds(1)); _client.Connect(); }
public void Init() { try { _boltProtocol = _client.Connect(); _boltProtocol.Authenticate(this, _userAgent, _authToken); } catch (AggregateException e) { // To remove the wrapper around the inner exception because of Task.Wait() throw e.InnerException; } }
public void Connect(string host, int port) { if (IsConnected) { log.Warn("Already connected"); return; } if (isConnecting) { log.Warn("A connection attempt is already in progress"); return; } if (config == null) { config = new ConfigData(); config.UseBlueBox = UseBlueBox; config.Debug = Debug; } if (host == null) { host = config.Host; } if (port == -1) { port = config.Port; } if (host == null || host.Length == 0) { throw new ArgumentException("Invalid connection host name / IP address"); } if (port < 0 || port > 65535) { throw new ArgumentException("Invalid connection port"); } lastHost = host; isConnecting = true; socketClient.Connect(host, port); }
/// <summary> /// 连接到移动设备 /// </summary> /// <param name="mobileIPAddress"></param> /// <returns></returns> public void ConnectToMobile(string mobileIPAddress, ConnectedCallback onConnectionEvent) { Log.I("mobileIPAddres:{0}", mobileIPAddress); mSocketClient = FlexiSocket.Create(mobileIPAddress, 1366, Protocols.BodyLengthPrefix); mSocketClient.Connected += onConnectionEvent; mSocketClient.Disconnected += OnDisconnected; mSocketClient.Received += OnReceived; mSocketClient.Sent += OnSent; mSocketClient.Connect(); //this.Repeat() // .Delay(1.0f) // .Event(() => { mSocketClient.Connect(); }) // .Begin(); }
private void Awake() { _client = new TcpSocketClient("127.0.0.1", 6666); _client.OnConnectCompletedEvent += Client_OnConnectCompletedEvent; _client.OnDisconnectCompletedEvent += Client_OnDisconnectCompletedEvent; _client.OnReceiveCompletedEvent += Client_OnReceiveCompletedEvent; _client.OnSendCompletedEvent += Client_OnSendCompletedEvent; _client.Connect(); }
private IEnumerator ConnectToServer(string serverIp) { if (!isWifiConnected && !isWifiConnecting) { Debug.Log(serverIp + ":------- .serverip>>>>>>>>>>>"); mSocketClient = FlexiSocket.Create(serverIp, 1366, Protocols.BodyLengthPrefix); mSocketClient.Connected += OnConnected; mSocketClient.Disconnected += OnDisconnected; mSocketClient.Received += OnReceived; mSocketClient.Sent += OnSent; yield return(new WaitForSeconds(1)); mSocketClient.Connect(); } }
public override BaseBuffer <ISocketClient <T> > Create() { SocketBuffer <T> buffer = new SocketBuffer <T>(); ISocketClient <T> client = NetFactory.CreateSocketClient <T>(this.NetName); if (lstSrv != null) { string srv = hashSrv.GetCurrent(); string[] srvAddrs = srv.Split(':'); if (srvAddrs.Length == 2) { client.Connect(srvAddrs[0], int.Parse(srvAddrs[1])); } } buffer.Data = client; return(buffer); }
/// <exception cref="ArgumentException"></exception> /// > /// <exception cref="SocketException"></exception> /// > public OperationResponseDto SendOperation(OperationDto operationDto) { //PRE-CONDITION //TODO LOGGING operationDto.Params.ToList() .ForEach(x => CodeContract.PreCondition <ArgumentException>(x >= 0 && x <= 65535)); var paramBytes = new List <byte>(); foreach (var param in operationDto.Params) { paramBytes.Add(GetDataType(param)); paramBytes.AddRange(ValueToBytes(param)); } var payload = new List <byte> { operationDto.Operation, operationDto.Device }.Concat(paramBytes).ToArray(); try { _socketClient.Connect(); _socketClient.Send(payload); var response = _socketClient.Recieve(); //POST-CONDITIONS //TODO LOGGING CodeContract.PostCondition <SocketException>( !response.SequenceEqual(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 })); CodeContract.PostCondition <ArgumentException>(response[1] > 0 && response[1] < 4); CodeContract.PostCondition <ArgumentException>(response[0] > 0); CodeContract.PostCondition <ArgumentException>(response.Length == 8); return(new OperationResponseDto { Status = response[0], Returns = BytesToValue(response.Skip(1).ToArray()) }); } finally { _socketClient.Close(); } }
/// <summary> /// 连接到移动设备 /// </summary> /// <param name="mobileIPAddress"></param> /// <returns></returns> public void ConnectToMobile(string mobileIPAddress, ConnectedCallback onConnectionEvent) { Log.I("mobileIPAddres:{0}", mobileIPAddress); mSocketClient = FlexiSocket.Create(mobileIPAddress, 1366, Protocols.BodyLengthPrefix); mSocketClient.Connected += onConnectionEvent; mSocketClient.Disconnected += OnDisconnected; mSocketClient.Received += OnReceived; mSocketClient.Sent += OnSent; DelayNode delayNode = new DelayNode(1.0f) { OnEndedCallback = delegate { mSocketClient.Connect(); } }; StartCoroutine(delayNode.Execute()); }
/// <summary> /// 连接指定的服务器。 /// </summary> public bool Connect(Server server, AddressFamily addressFamily = AddressFamily.InterNetwork) { if (server == Server.PServer) { var ip = PrefsUtil.GetString(TestLoginRecord.PServerTestLoginIp, null); var port = PrefsUtil.GetInt(TestLoginRecord.PServerTestLoginPort, 0); if (string.IsNullOrEmpty(ip) || port == 0) { return(false); } var socketFactory = _context.GetSocketFactory(); _socket = socketFactory.CreateSocket(); return(_socket.Connect(ip, port, server, addressFamily)); } return(false); }
/// <summary> /// 连接指定的服务器。 /// </summary> public bool Connect(Server server, AddressFamily addressFamily = AddressFamily.InterNetwork) { _networkAddressFamily = addressFamily; if (_socket != null) { _socket.Close(); _socket = null; } if (server == Server.Null || server == Server.CServer) { // 其他的服务器就不用连接了。 return(false); } var hServerAddress = _hServerAddress.Read(); var gServerAddress = _gServerAddress.Read(); string host = ""; int port = 0; switch (server) { case Server.PServer: host = GetHost(); port = GetPort(); break; case Server.HServer: host = hServerAddress; port = 11122; break; case Server.GServer: if (gServerAddress == null) { MyLog.ErrorWithFrame( name, string.Format("GameServer Address Error ") ); return(false); } host = gServerAddress.Ip; port = gServerAddress.Port; break; default: break; } MyLog.InfoWithFrame( name, string.Format("Connect gate server: {0}:{1}", host, port) ); #if UNITY_IOS var ios = _context.GetIosSDK(); if (addressFamily == AddressFamily.InterNetworkV6) { host = ios.GetIpV6(host); MyLog.InfoWithFrame(name, string.Format("convert to ipv6: {0}", host)); } #endif if (string.IsNullOrEmpty(host)) { return(false); } var socketFactory = _context.GetSocketFactory(); _socket = socketFactory.CreateSocket(); return(_socket.Connect(host, port, server, addressFamily)); }