Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 /// <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);
     }
 }
Exemplo n.º 3
0
 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);
     }
 }
Exemplo n.º 4
0
 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;
     }
 }
Exemplo n.º 5
0
 public void ProcessMessagesInBackground()
 {
     asyncMessageProcessor = new ParallelTaskStarter(TimeSpan.Zero);
     asyncMessageProcessor.Start(async() => await IncomingMessageHandler.ProcessNetworkMessages(Host));
 }