/// <summary> /// Helper method for Gem.Network.Tests.MessageEncodingTests.SuccessfulDecodeTest() /// Set's up a server and sends a message for decoding /// This is done in a seperate project because a socket exception is thrown /// because client / server use the same port /// </summary> public static void MessageDecodingTestHelper() { var server = new NetworkServer(); //server.Connect(new ServerConfig { Name = "local", Port = 14241 }); NetIncomingMessage inc; while (true) { if ((inc = server.ReadMessage()) != null) { switch (inc.MessageType) { case NetIncomingMessageType.ConnectionApproval: Console.WriteLine("Incoming LOGIN"); inc.SenderConnection.Approve(); break; case NetIncomingMessageType.Data: var outgoingmessage = server.CreateMessage(); var obj = new ClassToSerialize(); obj.StringProperty = "SomeString"; MessageSerializer.Encode(obj, ref outgoingmessage); server.SendToAll(outgoingmessage); Console.WriteLine("Sended a package with some string"); break; } } } }
public void SendNotification(Notification notification) { var msg = client.CreateMessage(); MessageSerializer.Encode(notification, ref msg); client.SendMessage(msg, PackageConfig.DeliveryMethod, PackageConfig.SequenceChannel); }
public void SendMessage <T>(T message) { var msg = client.CreateMessage(); MessageSerializer.Encode(message, ref msg); client.SendMessage(msg, PackageConfig.DeliveryMethod, PackageConfig.SequenceChannel); }
public ServerCommandHost(IServer commandHost) { Guard.That(commandHost, "Command host must not be null").IsNotNull(); this.commandHost = commandHost; executioners = new Stack <ICommandExecutioner>(); commandTable = new Dictionary <string, CommandInfo>(); EchoToAll = new DebugHost(); EchoToAll.RegisterAppender(new ActionAppender(commandHost.NotifyAll)); //Setup echo to respond only to the defined connection Echo = (msg, connection) => { var om = commandHost.CreateMessage(); var serverNotification = new Notification(msg, NotificationType.Message); MessageSerializer.Encode(serverNotification, ref om); GemNetworkDebugger.Append.Info(msg); commandHost.SendOnlyTo(om, connection); }; RegisterHelpComand(); RegisterSetPasswordCommand(); RegisterEchoCommand(); RegisterKickCommand(); RegisterViewClientsCommand(); //the default password Password = "******"; }
public void SendNotification(Notification notification) { GemNetworkDebugger.Append.Info(String.Format("Sent to all : {0} of type {1}", notification.Message, notification.Type)); var om = netServer.CreateMessage(); MessageSerializer.Encode(notification, ref om); SendToAll(om); }
public void SendMessage <T>(T message, byte id) { var msg = netServer.CreateMessage(); MessageSerializer.Encode(message, ref msg); msg.Write(id); netServer.SendToAll(msg, packageConfig.DeliveryMethod); }
public void SendMessage <T>(object[] args) { var om = client.CreateMessage(); var msg = (T)Activator.CreateInstance(typeof(T), args); MessageSerializer.Encode(msg, ref om); client.SendMessage(om, PackageConfig.DeliveryMethod, PackageConfig.SequenceChannel); }
public void NotifyAllExcept(string message, NetConnection client, string type = NotificationType.Message) { GemNetworkDebugger.Append.Info(String.Format("Sent to all : {0}", message)); var serverNotification = new Notification(message, type); var om = netServer.CreateMessage(); MessageSerializer.Encode(serverNotification, ref om); SendAndExclude(om, client); }
public void NotifyAll(string message) { GemNetworkDebugger.Append.Info(String.Format("Sent to all : {0}", message)); var serverNotification = new Notification(message, NotificationType.Message); var om = netServer.CreateMessage(); MessageSerializer.Encode(serverNotification, ref om); SendToAll(om); }
public void SendMessageWithLocalTime <T>(T message, byte id) { var msg = client.CreateMessage(); MessageSerializer.Encode(message, ref msg); msg.Write(id); msg.WriteTime(NetTime.Now, true); client.SendMessage(msg, PackageConfig.DeliveryMethod, PackageConfig.SequenceChannel); }
public void SendMessage <T>(NetConnection sender, T message, byte id) { var msg = netServer.CreateMessage(); MessageSerializer.Encode(message, ref msg); msg.Write(id); netServer.SendToAll(msg, sender, packageConfig.DeliveryMethod, packageConfig.SequenceChannel); }
public void NotifyOnly(string message, NetConnection client, string type = NotificationType.Message) { if (client != null) { GemNetworkDebugger.Append.Info(String.Format("{0} : {1}", client, message)); var serverNotification = new Notification(message, type); var om = netServer.CreateMessage(); MessageSerializer.Encode(serverNotification, ref om); SendOnlyTo(om, client); } else { GemNetworkDebugger.Append.Info(String.Format("Server : {0}", message)); } }
public static void DynamicMessageDecodingTestHelper() { #region Dynamic Type var propertyList = new List <RuntimePropertyInfo> { new RuntimePropertyInfo { PropertyName = "Name", PropertyType = typeof(string) } }; IPocoBuilder PocoBuilder = new ReflectionEmitBuilder(); Type myNewType = PocoBuilder.Build("POCO", propertyList); dynamic myObject = Activator.CreateInstance(myNewType); myObject.Name = "DynamicType"; #endregion NetworkServer server; server = new NetworkServer(); //server.Connect(new ServerConfig { Name = "local", Port = 14241 }); NetIncomingMessage inc; while (true) { if ((inc = server.ReadMessage()) != null) { switch (inc.MessageType) { case NetIncomingMessageType.ConnectionApproval: Console.WriteLine("Incoming LOGIN"); inc.SenderConnection.Approve(); break; case NetIncomingMessageType.Data: var outgoingmessage = server.CreateMessage(); MessageSerializer.Encode(myObject, ref outgoingmessage); server.SendToAll(outgoingmessage); Console.WriteLine("Sended a package with some string"); break; } } } }