static void Init1() { ConsoleHelper.WriteLine("WSServer 正在初始化....", ConsoleColor.Green); _server = new WSServer(); _server.OnMessage += Server_OnMessage; _server.Start(); ConsoleHelper.WriteLine("WSServer 就绪,回车启动客户端", ConsoleColor.Green); ConsoleHelper.ReadLine(); WSClient client = new WSClient(); client.OnPong += Client_OnPong; client.OnMessage += Client_OnMessage; client.OnError += Client_OnError; client.OnDisconnected += Client_OnDisconnected; ConsoleHelper.WriteLine("WSClient 正在连接到服务器...", ConsoleColor.DarkGray); var connected = client.Connect(); if (connected) { ConsoleHelper.WriteLine("WSClient 连接成功,回车测试消息", ConsoleColor.DarkGray); ConsoleHelper.ReadLine(); //client.Close(); //ConsoleHelper.ReadLine(); var loop = true; Task.Run(() => { while (loop) { ConsoleHelper.WriteLine("WSClient 正在发送消息...", ConsoleColor.DarkGray); client.Send($"hello world!{DateTime.Now.ToString("HH:mm:ss.fff")}"); Thread.Sleep(1000); } }); ConsoleHelper.ReadLine(); loop = false; ConsoleHelper.WriteLine("WSClient 正在ping服务器...", ConsoleColor.DarkGray); Thread.Sleep(2000); client.Ping(); ConsoleHelper.ReadLine(); ConsoleHelper.WriteLine("WSClient 正在断开连接..."); Thread.Sleep(1000); client.Close(); } else { ConsoleHelper.WriteLine("WSClient 连接失败", ConsoleColor.DarkGray); } }
void InitNetwork() { WSServerState.Reset(); if (DebugStandalone) { WSServer.Stop(); WSServerState.Reset(); WSClient.Disconnect(); WSClientState.Reset(); WSServer.StartFake(); WSClient.ConnectFake(); } else if (IsClient) { WSServer.Stop(); WSServerState.Reset(); WSClient.Connect(); } else { WSClient.Disconnect(); WSClientState.Reset(); if (!WSServer.IsRunning) { WSServer.Start(); } } }
public async void WSTryConnect() { ILog rsp = WSRemoteEndPoint.Initialize(); if (rsp != null) { rsp.Print(); return; } wsClient = new WSClient(WSRemoteEndPoint, WSClientState); // this blocks but the main thread still goes on so Unity continues as normal rsp = await wsClient.Connect(); if (rsp != null) { rsp.Print(); return; } rsp = await wsClient.Listen(); if (rsp != null) { rsp.Print(); return; } }
static void Init1() { WebHost webHost = new WebHost(port: 18080, root: "Html"); webHost.Start(); ConsoleHelper.WriteLine("WSServer 正在初始化....", ConsoleColor.Green); _server = new WSServer(); _server.OnMessage += Server_OnMessage; _server.OnDisconnected += _server_OnDisconnected; _server.Start(); ConsoleHelper.WriteLine("WSServer 就绪,回车启动客户端", ConsoleColor.Green); ConsoleHelper.ReadLine(); WSClient client = new WSClient(); client.OnPong += Client_OnPong; client.OnMessage += Client_OnMessage; client.OnError += Client_OnError; client.OnDisconnected += Client_OnDisconnected; ConsoleHelper.WriteLine("WSClient 正在连接到服务器...", ConsoleColor.DarkGray); var connected = client.Connect(); if (connected) { ConsoleHelper.WriteLine("WSClient 连接成功,回车测试消息", ConsoleColor.DarkGray); ConsoleHelper.ReadLine(); //client.Close(); //ConsoleHelper.ReadLine(); ConsoleHelper.WriteLine("WSClient 正在发送消息...", ConsoleColor.DarkGray); client.Send($"hello world!{DateTime.Now.ToString("HH:mm:ss.fff")}"); ConsoleHelper.ReadLine(); ConsoleHelper.WriteLine("WSClient 正在ping服务器...", ConsoleColor.DarkGray); client.Ping(); ConsoleHelper.ReadLine(); ConsoleHelper.WriteLine("WSClient 正在断开连接..."); client.Close(); ConsoleHelper.ReadLine(); } else { ConsoleHelper.WriteLine("WSClient 连接失败", ConsoleColor.DarkGray); } }
public void BtnModeIP_OnClick(bool _isPerformer) { if (isDemo) { GameObject.Find("DEMO").GetComponent <DemoManager>().isCustomizeMode = _isPerformer; UnityEngine.SceneManagement.SceneManager.LoadScene(_isPerformer ? "Customize" : "Like"); return; } ws.Addr = _InputIP.text; _LabelIPMode.text = "接続中です..."; Canvas.ForceUpdateCanvases(); isCustomizeMode = _isPerformer; var res = ws.RequestHTTP(Method.GET, "check"); if (res == null) { // 接続不可 _LabelIPMode.color = Color.red; _LabelIPMode.fontSize = 32; _LabelIPMode.text = "サーバに接続することができませんでした" + Environment.NewLine + "IPアドレスをご確認ください"; return; } else if (res != "authenticated" && isCustomizeMode) { // パフォーマーモード // Pin認証 TransitionView("Forward", PinView); } // キャリブレーション待機画面へ TransitionView("Forward", CalibWaitView); ws.Connect(isCustomizeMode, res == "authenticated"); }
static void Init4() { ConsoleHelper.WriteLine("WSClient 正在连接到WorkMan服务器...", ConsoleColor.DarkGray); var url = "ws://123.207.136.134:9010/ajaxchattest"; WSClient client = new WSClient(url, SubProtocolType.Empty, "http://coolaf.com"); client.OnPong += Client_OnPong; client.OnMessage += Client_OnMessage; client.OnError += Client_OnError; client.OnDisconnected += Client_OnDisconnected; var connected = client.Connect(); if (connected) { ConsoleHelper.WriteLine("WSClient 连接成功,回车测试消息", ConsoleColor.DarkGray); ConsoleHelper.ReadLine(); client.Ping(); ConsoleHelper.WriteLine("WSClient 正在发送消息...", ConsoleColor.DarkGray); client.Send($"1111"); client.Send($"1111"); client.Send($"1111"); ConsoleHelper.WriteLine("WSClient 已发送消息", ConsoleColor.DarkGray); ConsoleHelper.WriteLine("回车WSClient 断开连接"); ConsoleHelper.ReadLine(); client.Close(); } else { ConsoleHelper.WriteLine("WSClient 连接失败", ConsoleColor.DarkGray); } }
static void Init3() { ConsoleHelper.WriteLine("WSClient 正在连接到WorkMan服务器...", ConsoleColor.DarkGray); var url = "ws://120.79.233.58:7272"; WSClient client = new WSClient(url, SubProtocolType.Json); client.OnPong += Client_OnPong; client.OnMessage += Client_OnMessage; client.OnError += Client_OnError; client.OnDisconnected += Client_OnDisconnected; var connected = client.Connect(); if (connected) { ConsoleHelper.WriteLine("WSClient 连接成功,回车测试消息", ConsoleColor.DarkGray); ConsoleHelper.ReadLine(); client.Ping(); ConsoleHelper.WriteLine("WSClient 正在发送消息...", ConsoleColor.DarkGray); client.Send($"hello world!{DateTime.Now.ToString("HH:mm:ss.fff")}"); ConsoleHelper.WriteLine("WSClient 已发送消息", ConsoleColor.DarkGray); ConsoleHelper.ReadLine(); ConsoleHelper.WriteLine("回车WSClient 断开连接"); ConsoleHelper.ReadLine(); client.Close(); ConsoleHelper.ReadLine(); } else { ConsoleHelper.WriteLine("WSClient 连接失败", ConsoleColor.DarkGray); } }