public Peer(string name) { CanAppend = true; IncomingMessages = new ConcurrentQueue <string>(); this.Name = name; protocolExample = GemClient.Profile("GemChat") .CreateNetworkProtocolEvent <Package>() .HandleIncoming((sender, package) => { QueueMessage(String.Format("Server sent {0} {1}", sender.Statistics.SentBytes, package.Name)); }) .GenerateSendEvent(); onEvent = GemClient.Profile("GemChat") .CreateNetworkEvent .AndHandleWith(this, x => new Action <string>(x.QueueMessage)); onCommandExecute = GemClient.Profile("GemChat") .CreateNetworkEvent .AndHandleWith(this, x => new Action <string>(x.ExecuteCommand)); onEvent.Send(name + " has joined"); messageAppender = new ParallelTaskStarter(TimeSpan.Zero); messageAppender.Start(DequeueIncomingMessages); }
/// <summary> /// Tries to connect and starts receiving / sending messages /// </summary> /// <param name="ApprovalMessageDelegate">A delegate that returns a connection approval message thats handled by the server</param> public void RunAsync(Func <ConnectionApprovalMessage> ApprovalMessageDelegate) { try { client.Connect(connectionDetails, PackageConfig, ApprovalMessageDelegate()); asyncMessageProcessor.Start(() => messageProcessor.ProcessNetworkMessages()); } catch (Exception ex) { GemNetworkDebugger.Append.Error("Unable to connect to {0} . Reason: {1}", connectionDetails.ServerIP, ex.Message); } }
public void RunAsync() { try { server.Connect(serverConfig, PackageConfig); asyncMessageProcessor.Start(() => messageProcessor.ProcessNetworkMessages()); } catch (Exception ex) { GemNetworkDebugger.Append.Error("Unable to start the server. Reason: {0}", ex.Message); } }
private void AnimateFrames(bool animate) { if (updateLoop == null && animate) { updateLoop = new ParallelTaskStarter(TimeSpan.FromMilliseconds(5)); animationPosition = () => new Vector2(animation.Settings.TileSheetWidth / 2 - animation.Settings.FrameWidth / 2, animation.Settings.TileSheetHeight / 2 - animation.Settings.FrameHeight / 2); updateLoop.Start(() => { animation.Update(updateLoop.ElapsedTime); ReDraw(); }); output.AppendLine( $"Animating frames {animation.Settings.StartFrame} - {animation.Settings.LastFrame} with {animation.Settings.FrameDelay * 1000} ms delay"); } if (updateLoop != null && !animate) { updateLoop.Stop(); updateLoop = null; } }
public void ProcessMessagesInBackground() { asyncMessageProcessor = new ParallelTaskStarter(TimeSpan.Zero); asyncMessageProcessor.Start(async() => await IncomingMessageHandler.ProcessNetworkMessages(Host)); }