static void Main(string[] args) { NetPeerConfiguration config = new NetPeerConfiguration("LidgrenTestServer"); config.AutoFlushSendQueue = false; var s_client = new NetClient(config); s_client.Start(); NetOutgoingMessage hail = s_client.CreateMessage("This is the hail message"); s_client.Connect("localhost", 14242, hail); NetIncomingMessage msg; while (true) { if ((msg = s_client.ReadMessage()) != null) { Console.WriteLine(msg.ReadString()); s_client.Recycle(msg); } Thread.Sleep(20); } }
/// <summary> /// /// </summary> /// <param name="message"></param> void DispatchIM ( NetClient client ) { NetIncomingMessage msg; while ((msg = client.ReadMessage()) != null) { switch (msg.MessageType) { case NetIncomingMessageType.VerboseDebugMessage:Log.Debug ("UI Net: " + msg.ReadString()); break; case NetIncomingMessageType.DebugMessage: Log.Verbose ("UI Net: " + msg.ReadString()); break; case NetIncomingMessageType.WarningMessage: Log.Warning ("UI Net: " + msg.ReadString()); break; case NetIncomingMessageType.ErrorMessage: Log.Error ("UI Net: " + msg.ReadString()); break; case NetIncomingMessageType.DiscoveryResponse: DiscoveryResponse( msg.SenderEndPoint, msg.ReadString() ); break; //case NetIncomingMessageType.StatusChanged: // var status = (NetConnectionStatus)msg.ReadByte(); // var message = msg.ReadString(); // Log.Message("UI: {0} - {1}", status, message ); // break; //case NetIncomingMessageType.Data: // var netCmd = (NetCommand)msg.ReadByte(); // state.DataReceived( netCmd, msg ); // break; default: Log.Warning("CL: Unhandled type: " + msg.MessageType); break; } client.Recycle(msg); } }
/// <summary> /// /// </summary> /// <param name="message"></param> void DispatchIM ( NetClient client ) { NetIncomingMessage msg; while ((msg = client.ReadMessage()) != null) { switch (msg.MessageType) { case NetIncomingMessageType.VerboseDebugMessage:Log.Debug ("CL Net: " + msg.ReadString()); break; case NetIncomingMessageType.DebugMessage: Log.Verbose ("CL Net: " + msg.ReadString()); break; case NetIncomingMessageType.WarningMessage: Log.Warning ("CL Net: " + msg.ReadString()); break; case NetIncomingMessageType.ErrorMessage: Log.Error ("CL Net: " + msg.ReadString()); break; case NetIncomingMessageType.ConnectionLatencyUpdated: ping = msg.ReadFloat(); if (Game.Network.ShowLatency) { Log.Verbose("...CL ping - {0} {1,6:0.00} ms", msg.SenderEndPoint, (ping*1000) ); } break; case NetIncomingMessageType.StatusChanged: var status = (NetConnectionStatus)msg.ReadByte(); var message = msg.ReadString(); Log.Message("CL: {0} - {1}", status, message ); state.StatusChanged( status, message, msg.SenderConnection ); break; case NetIncomingMessageType.Data: var netCmd = (NetCommand)msg.ReadByte(); state.DataReceived( netCmd, msg ); break; default: Log.Warning("CL: Unhandled type: " + msg.MessageType); break; } client.Recycle(msg); } }