/// <summary> /// 当前服务器连接是否正常 /// </summary> /// <returns></returns> public static bool ServiceTest() { if (mc == null) { mc = new MessageClient(_ip, _port); } if (mc.Connect()) { return(true); } return(false); }
/// <summary> /// 当前服务器连接是否正常 /// </summary> /// <returns></returns> public static bool ServiceTest() { if (mc == null) { mc = new MessageClient(GlobalStaticObj_Server.Instance.CloundServerIp, GlobalStaticObj_Server.Instance.CloundServerPort); } if (mc.Connect()) { return(true); } return(false); }
/// <summary> /// 开启客户版客户端 /// </summary> public void Start() { httpProxy = new HttpProxy(); _MouseAndKeyHelper = new MouseAndKeyHelper(); _mCleint = new MessageClient(this._userName, this.Dgcode); _mCleint.OnMessage += webCient_OnMessage; _mCleint.OnNotice += _mClient_OnNotice; var isConnected = _mCleint.Connect(); _mCleint.isCloseing = false; cts = new CancellationTokenSource(); if (timer == null) { timer = new System.Windows.Forms.Timer(); } timer.Interval = 1000;//每秒查询一次鼠标和键盘休闲时间 timer.Tick += new EventHandler(timer_Event); }
/// <summary> /// 启动远程服务器功能(1.绘制屏幕2.收集并发送鼠标键盘命令) /// </summary> /// <param name="userName"></param> public void Init(string lastID, string userName) { this._username = userName; _lastID = lastID; _mClient = new MessageClient(userName); _mClient.OnFile += _mClient_OnFile; _mClient.ReConnectFaild += _mClient_ReConnectFaild; _mClient.OnNotice += _mClient_OnNotice; _mClient.OnError += onError; _mClient.OnMsg += onMsg; _mClient.OnMessage += _mClient_OnMessage; _isConnected = _mClient.Connect(); while (!_isConnected) { Thread.Sleep(10); } if (!_isConnected) { OnConnectedFaild(); } else { _isConnected = true; } }
private static void ChannelMsgTest() { ConsoleHelper.WriteLine("发布订阅测试开始..."); var channelName = "testChannel"; var cc1 = new MessageClient(); cc1.Connect(); cc1.Subscribe(channelName); List <MessageClient> list = new List <MessageClient>(); Task.Run(() => { ConsoleHelper.WriteLine("正在开始初始化客户端..."); for (int i = 0; i < 10000; i++) { var ccc = new MessageClient(); ccc.OnChannelMessage += Ccc_OnChannelMessage; list.Add(ccc); } ConsoleHelper.WriteLine("正在建立连接..."); Parallel.ForEach(list, (item) => { item.Connect(); }); ConsoleHelper.WriteLine("正在订阅..."); Parallel.ForEach(list, (item) => { item.Subscribe(channelName); }); ConsoleHelper.WriteLine("正在转发..."); cc1.SendChannelMsg(channelName, channelName); Task.Run(() => { while (true) { ConsoleHelper.WriteLine("当前已接收到消息数:" + cmc); Thread.Sleep(1000); Interlocked.Increment(ref calc); if (cmc >= 10000) { ConsoleHelper.WriteLine("测试完毕,当前用时:" + calc + "秒"); break; } } }); }); ConsoleHelper.ReadLine(); }
public void ConnectToOperator(MessageTransfer.EndPoint serverEndPoint) { messageClientToServer.Connect(serverEndPoint.ToIPEndPoint()); var p2pRequest = new P2PRequest { UserEmail = this.Email, UserID = this.ID, UserName = this.Name }; messageClientToServer.SendMessage(p2pRequest); }
public void Start(string userName, string channelID) { _userName = userName; _channelID = channelID; Client = new MessageClient(10240, clientConfig.IP, clientConfig.Port); Client.OnChannelMessage += Client_OnChannelMessage; Client.OnPrivateMessage += Client_OnPrivateMessage; Client.OnError += Client_OnError; Client.Connect(); Client.Login(); Client.Subscribe(channelID); }
public void Connect(string serverIp, int serverPort) { netClient.Connect(serverIp, serverPort); Thread.Sleep(1000); System.Timers.Timer heartbeatTimer = new System.Timers.Timer(kHeartbeatInterval); heartbeatTimer.Elapsed += new System.Timers.ElapsedEventHandler((sender, e) => { if (session.isLogin && session.user.uid != string.Empty) { Heartbeat(); } }); heartbeatTimer.Start(); }
static void PerformanceTest() { ConsoleHelper.WriteLine("回车开始私信测试开始..."); ConsoleHelper.ReadLine(); var cc1 = new MessageClient(); cc1.OnPrivateMessage += Client_OnPrivateMessage1; var cc2 = new MessageClient(); cc2.OnPrivateMessage += Client_OnPrivateMessage1; cc1.Connect(); cc2.Connect(); cc1.Login(); cc2.Login(); Stopwatch stopwatch = Stopwatch.StartNew(); int size = 100000; TaskHelper.LongRunning(() => { for (int i = 0; i < size; i++) { cc1.SendPrivateMsg(cc2.ID, "你好呀,cc2!"); cc2.SendPrivateMsg(cc1.ID, "你好呀,cc2!"); } }); while (true) { if (_pcount < 2 * size) { ConsoleHelper.WriteLine($"已处理私信{_pcount}条"); Thread.Sleep(1000); } else { stopwatch.Stop(); ConsoleHelper.WriteLine($"私信测试已完成,速度:{_pcount / stopwatch.Elapsed.TotalSeconds}"); break; } } ConsoleHelper.WriteLine("回车开始频道测试开始..."); ConsoleHelper.ReadLine(); }
public void ConnectToUser(MessageTransfer.EndPoint serverEndPoint) { messageServer = new MessageServer(); messageServer.MessageReceived += MessageServer_MessageReceived; messageServer.Start(); messageClient.Connect(serverEndPoint.ToIPEndPoint()); ReadyRequest readyRequest = new ReadyRequest { EndPoint = messageServer.ListeningEndPoint, OperatorID = ID }; messageClient.SendMessage(readyRequest); }
private void MessageClientToServer_MessageReceived(Message message, IPEndPoint endPoint) { if (message is P2PResponse) { messageClientToServer.CloseConnection(); var response = message as P2PResponse; var operatorEndPoint = response.ListeningEndPoint; messageClientToOperator.Connect(operatorEndPoint.ToIPEndPoint()); Introduction introduction = new Introduction { Name = Name }; SendMessage(introduction); } }
protected override void Run() { server.StartOnlineServer(); client.Connect(10); //Thread generateLinkers = new Thread(Generate); Thread generateLinkers = new Thread(GenerateFixed); Thread autoReleaseBuffer = new Thread(AutoSubmitSimulation); generateLinkers.Start(); autoReleaseBuffer.Start(); generateLinkers.Join(); autoReleaseBuffer.Join(); client.DisConnect(); server.ShutDownOnlineServer(); }
public IEnumerator Login() { IsCompleteSendMessage = false; if (Client.IsInitialized == false) { var task = Client.Connect(IPAddress, PortNo); if (task == null) {// 接続タスク 終了 yield break; } } Debug.Log("LoginTask connecting"); while (!Client.IsActive) { if (Client.IsInitialized) {// 初期化待ち yield return(null); } else {// 内部エラー発生 Debug.Log("Abort ConnectTask"); yield break; } } Debug.Log("LoginTask connected"); WaitRecieveUserInfo = true; Client.Login(UserInfo); while (WaitRecieveUserInfo) { if (!Client.IsActive) { Debug.Log("Abort ConnectTask WaitRecieveUserInfo"); yield break; } // ログイン情報を取得するまで待機 yield return(null); } IsCompleteSendMessage = true; }
public void Run(int serverPort) { client = new MessageClient( new FramedClient(new SocketClient(useIPv6: true)), new ProtoBufStacksSerializer(), new ClientMessageHandler()); client.PreLoadTypesFromAssemblyOfType <TemperatureResponse>(); client.Connect(new IPEndPoint(IPAddress.IPv6Loopback, serverPort)) .Subscribe(_ => { Console.WriteLine("Querying for temperature in London, Warsaw, Madrid"); client.Send(new TemperatureRequest { City = "London" }); client.Send(new TemperatureRequest { City = "Warsaw" }); client.Send(new TemperatureRequest { City = "Madrid" }); }); }
private static void FunTest() { //=============================================================== ConsoleHelper.WriteLine("回车开始私信测试开始..."); ConsoleHelper.ReadLine(); var cc1 = new MessageClient(); cc1.OnPrivateMessage += Client_OnPrivateMessage; var cc2 = new MessageClient(); cc2.OnPrivateMessage += Client_OnPrivateMessage; cc1.Connect(); cc2.Connect(); cc1.Login(); cc2.Login(); Task.Run(() => { while (true) { cc1.SendPrivateMsg(cc2.UserToken.ID, "你好呀,cc2!"); cc2.SendPrivateMsg(cc1.UserToken.ID, "你好呀,cc1!"); Thread.Sleep(500); } }); //=============================================================== ConsoleHelper.WriteLine("回车开始频道测试开始..."); ConsoleHelper.ReadLine(); MessageClient client = new MessageClient(); client.OnChannelMessage += Client_OnChannelMessage; ConsoleHelper.WriteLine("客户正在连接..."); string channelName = "频道测试一"; client.Connect(); ConsoleHelper.WriteLine("客户端就绪"); client.Login(); ConsoleHelper.WriteLine("客户端登录成功"); client.Subscribe(channelName); ConsoleHelper.WriteLine("客户端订阅成功"); Task.Run(() => { while (true) { client.SendChannelMsg(channelName, "hello!"); Thread.Sleep(500); } }); //=============================================================== ConsoleHelper.WriteLine("回车开始订阅频道消息..."); ConsoleHelper.ReadLine(); List <MessageClient> list = new List <MessageClient>(); Task.Factory.StartNew(() => { for (int i = 0; i < 100; i++) { var c = new MessageClient(); if (i < 10) { c.OnChannelMessage += Client_OnChannelMessage2; } list.Add(c); c.Connect(); c.Login(); c.Subscribe(channelName); } }); //=============================================================== ConsoleHelper.WriteLine("回车开始群组测试"); ConsoleHelper.ReadLine(); cc1.OnGroupMessage += Client_OnGroupMessage; cc2.OnGroupMessage += Client_OnGroupMessage; var groupName = "萌一号蠢"; cc1.SendCreateGroup(groupName); cc2.SendAddMember(groupName); Task.Run(() => { while (true) { cc1.SendGroupMessage(groupName, "群主广播了!"); cc2.SendGroupMessage(groupName, "群主万岁!"); Thread.Sleep(100); } }); ConsoleHelper.ReadLine(); ConsoleHelper.WriteLine("The function test has been completed."); //=============================================================== cc2.SendRemoveMember(groupName); cc1.SendRemoveGroup(groupName); client.Unsubscribe(channelName); }
public void Connect(string server_ip, int server_port) { net_client.Connect(server_ip, server_port); Thread.Sleep(1000); }