private void SendHeartBeat() { var time = MyGameTime.time; if (time - _lastHeartBeatTime > MAX_HEARTBEAT_INTERVAL) { _lastHeartBeatTime = time; foreach (var channel in _connectedChannels) { if (channel.IsConnected) { var msg = HeartBeatMessage.Allocate(); channel.SendReliable((int)EServer2ClientMessage.HeartBeat, msg); msg.ReleaseReference(); } else { _disconnectedChannel.Add(channel); } } if (_disconnectedChannel.Count > 0) { foreach (var channel in _disconnectedChannel) { _connectedChannels.Remove(channel); } _disconnectedChannel.Clear(); } } }
void HeartBeat() { HeartBeatMessage msg = new HeartBeatMessage(); msg.cmd = "heartbeat"; Byte[] sendBytes = Encoding.ASCII.GetBytes(JsonUtility.ToJson(msg)); udp.Send(sendBytes, sendBytes.Length); }
private void CheckHeartBeat() { if (_clientChannel != null && _stopwatch.ElapsedMilliseconds - _lastHeartBeatTime > _checkHeartBeatTime) { var msg = HeartBeatMessage.Allocate(); msg.Id = SingletonManager.Get <ServerFileSystemConfigManager>().BootConfig.Id; SendAndReleaseMessage(_clientChannel, RpcMessageType.ServerHeartBeat, msg); _lastHeartBeatTime = _stopwatch.ElapsedMilliseconds; } }
public static void HandleHeartBeat(HeartBeatMessage message, LoLClient client) { if (message.receiveTime > message.ackTime) { var diff = message.ackTime - message.receiveTime; var msg = $"Player {client.Hero.Name} sent an invalid heartbeat - Timestamp error (diff: {diff})"; logger.Write(msg, MessageState.WARNING); } }
public void ProcessHeartbeatMessage(HeartBeatMessage hbm) { if (_Client == null) { return; } if (_HeartbeatMessageDelegate != null) { _HeartbeatMessageDelegate(); } }
void HeartBeatMessageToServer() //tell server client is connected every second { if (!heartbeating) //stop heart if it is dced from losing connection on client side { CancelInvoke(); return; } var payload = new HeartBeatMessage { header = socketMessagetype.HEARTBEAT, }; var data = Encoding.ASCII.GetBytes(JsonUtility.ToJson(payload)); udp.Send(data, data.Length); gmScript.HeartbeatfromClient(); }
private void CheckHeartBeat(HeartBeatMessage message) { string peerName = message.header.Sender; DateTime hbTime = message.header.TimeStamp; lock (_hbDictionary) { if (_heartBeats.ContainsKey(peerName)) { _heartBeats[peerName] = hbTime; } else { _heartBeats.Add(peerName, hbTime); } } }
public void WhenHeartBeatMessageArrivesFromUnknownPeer_ItsHealthUriIsDisconnected() { var peerIdentifier = new ReceiverIdentifier(Guid.NewGuid().ToByteArray()); var healthUri = new Uri("tcp://127.0.0.1:80"); var payload = new HeartBeatMessage { SocketIdentity = peerIdentifier.Identity, HealthUri = healthUri.ToSocketAddress() }; var message = Message.Create(payload); subscriberSocket.SetupMessageReceived(message, tokenSource.Token); connectedPeerRegistry.Setup(m => m.Find(peerIdentifier)).Returns((ClusterMemberMeta)null); // clusterHealthMonitor.Start(); AsyncOp.Sleep(); tokenSource.Cancel(); clusterHealthMonitor.Stop(); // subscriberSocket.Verify(m => m.Disconnect(healthUri), Times.Once); }
static void Main(string[] args) { //test for pull request var msg = new HeartBeatMessage() { User = "******", Env = "DEV", Application = "test_app", TimeStamp = DateTime.Now }; Service.Instance.Subscrible(msg.User, msg.Env, msg.Application, (eventArgs) => Console.WriteLine(eventArgs)); Console.WriteLine("Input 'C' to exit, input any key to send message."); Task.Factory.StartNew(() => { while (true) { msg.TimeStamp = DateTime.Now; Service.Instance.Publish(msg.User, msg.Env, msg.Application, msg, true); Thread.Sleep(5000); } }); var input = Console.ReadLine(); var echoMsg = new EchoMessage() { User = "******", Env = "DEV", Application = "test_app", Echo = "Hello from Application" }; while (input.ToLower() != "c") { echoMsg.Echo = input; Service.Instance.Publish(echoMsg.User, echoMsg.Env, echoMsg.Application, echoMsg, true); input = Console.ReadLine(); } }
public void WhenHeartBeatMessageArrives_PeerLastKnwonHeartBeatIsSetToUtcNow() { var peerIdentifier = new ReceiverIdentifier(Guid.NewGuid().ToByteArray()); var payload = new HeartBeatMessage { SocketIdentity = peerIdentifier.Identity }; var message = Message.Create(payload); subscriberSocket.SetupMessageReceived(message, tokenSource.Token); var meta = new ClusterMemberMeta { LastKnownHeartBeat = DateTime.UtcNow - TimeSpan.FromHours(20) }; connectedPeerRegistry.Setup(m => m.Find(peerIdentifier)).Returns(meta); // clusterHealthMonitor.Start(); AsyncOp.Sleep(); tokenSource.Cancel(); clusterHealthMonitor.Stop(); // Assert.LessOrEqual(DateTime.UtcNow - meta.LastKnownHeartBeat, AsyncOp.MultiplyBy(3)); }
private void SendHeartBeat(CancellationToken token) { try { using (var socket = CreateHeartBeatSocket()) { var heartBeatMessage = new HeartBeatMessage { SocketIdentity = scaleOutConfigurationProvider.GetScaleOutAddress().Identity, HeartBeatInterval = config.GetHeartBeatInterval(), HealthUri = config.GetHeartBeatAddress().ToSocketAddress() }; while (!token.IsCancellationRequested) { try { socket.SendMessage(Message.Create(heartBeatMessage)); //logger.Debug($"HeartBeat sent at {DateTime.UtcNow} UTC"); config.GetHeartBeatInterval().Sleep(token); //await Task.Delay(config.GetHeartBeatInterval(), token); } catch (OperationCanceledException) { } catch (Exception err) { logger.Error(err); } } } } catch (Exception err) { logger.Error(err); } logger.Warn("HeartBeating stopped."); }
protected Message getMessage() { byte[] b; int avail; try { //while we're here, look for data in the buffer avail = _sock.Available; if (avail > 0) { buffer.ReadFromSocket(_sock, avail); this.BytesReceived += avail; } //first see if we can actually decode something if (buffer.CanDecode()) { b = buffer.Decode(); } else { return(null); } } catch (Exception ex) { PhazeXLog.LogError(ex, GameLibraryVersion.VersionString, 104); _connected = false; return(null); } Message m = null; if (b.Length == 0) { return(m); } else if (b[0] == (byte)pxMessages.Heartbeat) { m = new HeartBeatMessage(b); } else if (b[0] == (byte)pxMessages.ChangeName) { m = new ChangeNameMessage(b, this.GetPlayerIDs()); } else if (b[0] == (byte)pxMessages.ChangeNameReject) { m = new ChangeNameRejectMessage(b); } else if (b[0] == (byte)pxMessages.Chat) { m = new ChatMessage(b, this.GetPlayerIDs()); } else if (b[0] == (byte)pxMessages.CompletedPhaze) { m = new CompletedPhazeMessage(b, this.GetPlayerIDs()); } else if (b[0] == (byte)pxMessages.CurrentPhaze) { m = new CurrentPhazeMessage(b, this.GameRules); } else if (b[0] == (byte)pxMessages.DiscardSkip) { m = new DiscardSkipMessage(b, this.GetPlayerIDs(), this.GameRules); } else if (b[0] == (byte)pxMessages.DialogMessage) { m = new DialogMessage(b); } else if (b[0] == (byte)pxMessages.ErrorMessage) { m = new ErrorMessage(b); } else if (b[0] == (byte)pxMessages.GameOver) { m = new GameOverMessage(b); } else if (b[0] == (byte)pxMessages.GameRules) { m = new GameRulesMessage(b); } else if (b[0] == (byte)pxMessages.GameStarting) { m = new GameStartingMessage(b); } else if (b[0] == (byte)pxMessages.Goodbye) { m = new GoodbyeMessage(b); } else if (b[0] == (byte)pxMessages.GotCards) { m = new GotCardsMessage(b, this.GameRules); } else if (b[0] == (byte)pxMessages.GotDeckCard) { m = new GotDeckCardMessage(b, this.GetPlayerIDs()); } else if (b[0] == (byte)pxMessages.GotDiscard) { m = new GotDiscardMessage(b, this.GetPlayerIDs(), this.GameRules); } else if (b[0] == (byte)pxMessages.Hand) { m = new HandMessage(b, this.GameRules); } else if (b[0] == (byte)pxMessages.Login) { m = new LoginMessage(b); } else if (b[0] == (byte)pxMessages.LoginAcknowledgment) { m = new LoginAckMessage(b); } else if (b[0] == (byte)pxMessages.LogOff) { m = new LogOffMessage(b, this.GetPlayerIDs()); } else if (b[0] == (byte)pxMessages.NewHand) { m = new NewHandMessage(b); } else if (b[0] == (byte)pxMessages.PlayedCardOnTable) { m = new PlayedCardOnTableMessage(b, this.GetPlayerIDs(), this.GameRules); } else if (b[0] == (byte)pxMessages.Ready) { m = new ReadyMessage(b, this.GetPlayerIDs()); } else if (b[0] == (byte)pxMessages.Scoreboard) { m = new ScoreboardMessage(b, this.GetPlayerIDs(), this.GameRules); } else if (b[0] == (byte)pxMessages.SkipNotification) { m = new SkipNotificationMessage(b, this.GetPlayerIDs()); } else if (b[0] == (byte)pxMessages.StartGameTimer) { m = new StartGameTimerMessage(b); } else if (b[0] == (byte)pxMessages.Status) { m = new StatusMessage(b, this.GetPlayerIDs(), this.GameRules); } else if (b[0] == (byte)pxMessages.SystemMessage) { m = new SystemMessage(b); } else if (b[0] == (byte)pxMessages.Table) { m = new TableMessage(b, this.GameRules); } else if (b[0] == (byte)pxMessages.TurnEnd) { m = new TurnEndMessage(b, this.GetPlayerIDs()); } else if (b[0] == (byte)pxMessages.TurnStart) { m = new TurnStartMessage(b, this.GetPlayerIDs()); } else if (b[0] == (byte)pxMessages.UpdateDiscard) { m = new UpdateDiscardMessage(b, this.GetPlayerIDs(), this.GameRules); } else if (b[0] == (byte)pxMessages.WentOut) { m = new WentOutMessage(b, this.GetPlayerIDs()); } else if (b[0] == (byte)pxMessages.Won) { m = new WonMessage(b, this.GetPlayerIDs()); } else { m = new UnknownMessage(b); } return(m); }
private void handleHeartBeatMessage(HeartBeatMessage m, ServerPlayer p) { }
public void AddMessageToProcess(ServerPlayer sp, byte [] b) { if (b.Length < 1) { PhazeXLog.LogError ( new Exception("Attempted to process 0 byte message!") , GameLibraryVersion.ProgramIdentifier , 0 ); } byte start = b[0]; try { Message msg = null; switch (start) { case (byte)pxMessages.Heartbeat: msg = new HeartBeatMessage(b); break; case (byte)pxMessages.SystemMessage: msg = new SystemMessage(b); break; case (byte)pxMessages.Chat: msg = new ChatMessage(b, this.getIDs()); break; case (byte)pxMessages.Ready: msg = new ReadyMessage(b, this.getIDs()); break; case (byte)pxMessages.ChangeName: msg = new ChangeNameMessage(b, this.getIDs()); break; case (byte)pxMessages.PlayOnGroup: msg = new PlayOnGroupMessage(b, this.rules); break; case (byte)pxMessages.Meld: msg = new MeldMessage(b, this.rules); break; case (byte)pxMessages.GetTopDiscard: msg = new GetTopDiscardMessage(b); break; case (byte)pxMessages.GetTopDeckCard: msg = new GetTopDeckCardMessage(b); break; case (byte)pxMessages.DiscardSkip: msg = new DiscardSkipMessage(b, this.getIDs(), this.rules); break; case (byte)pxMessages.Discard: msg = new DiscardMessage(b, this.rules); break; case (byte)pxMessages.RequestHand: msg = new RequestHandMessage(b); break; case (byte)pxMessages.RequestTable: msg = new RequestTableMessage(b); break; default: msg = new UnknownMessage(b); break; } lock (this) { _messagesToProcess.Add(new PlayerMessage(sp, msg)); } } catch (BadMessageException bme) { PhazeXLog.LogError ( bme , GameLibraryVersion.ProgramIdentifier , 109 ); string info = ""; foreach (byte tmp in b) { info += ((int)tmp).ToString() + " "; } PhazeXLog.LogInformation(info, pid); } }