本文整理汇总了C#中IncomingMessage.DecodeFrom方法的典型用法代码示例。如果您正苦于以下问题:C# IncomingMessage.DecodeFrom方法的具体用法?C# IncomingMessage.DecodeFrom怎么用?C# IncomingMessage.DecodeFrom使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IncomingMessage
的用法示例。
在下文中一共展示了IncomingMessage.DecodeFrom方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: receiveLoop
private void receiveLoop()
{
while (IsRunning)
{
NetIncomingMessage msg = lidgrenClient.ReadMessage();
if (msg != null)
{
switch (msg.MessageType)
{
case NetIncomingMessageType.VerboseDebugMessage:
case NetIncomingMessageType.DebugMessage:
case NetIncomingMessageType.ErrorMessage:
case NetIncomingMessageType.WarningMessage:
Console.WriteLine(msg.ReadString());
break;
case NetIncomingMessageType.Data:
IncomingMessage im = new IncomingMessage();
im.DecodeFrom(msg);
Manager.MessageReceived(im, ContactPort);
OnMessageReceived(new MessageReceivedEventArgs(im));
break;
case NetIncomingMessageType.StatusChanged:
NetConnectionStatus status = (NetConnectionStatus)msg.ReadByte();
string reason = msg.ReadString();
Console.WriteLine(msg.SenderConnection + " status: " + status + " (" + reason + ")");
if (status == NetConnectionStatus.Disconnected && IsConnected)
{
Manager.Disconnected(msg.SenderEndpoint);
IsConnected = false;
}
else if (status == NetConnectionStatus.Connected)
IsConnected = true;
break;
default:
throw new InvalidOperationException("An unhandled MessageType was received.");
}
lidgrenClient.Recycle(msg);
}
Thread.Sleep(1);
}
}
示例2: receiveLoop
private void receiveLoop()
{
while (IsRunning)
{
NetIncomingMessage msg = lidgrenServer.ReadMessage();
if (msg != null)
{
switch (msg.MessageType)
{
case NetIncomingMessageType.DiscoveryRequest:
if (NetworkUtility.IsLocalIpAddress(msg.SenderEndpoint.Address.ToString()))
{
//-- Is it from this app? Send DiscoveryRequest only if its from a different app.
if (msg.SenderEndpoint.Port != Port)
{
Manager.DiscoveryRequestReceived(msg.SenderEndpoint, Port);
}
}
else
{
//-- It's from another machine.
Manager.DiscoveryRequestReceived(msg.SenderEndpoint, Port);
}
break;
case NetIncomingMessageType.VerboseDebugMessage:
case NetIncomingMessageType.DebugMessage:
case NetIncomingMessageType.ErrorMessage:
case NetIncomingMessageType.WarningMessage:
ServerUIShell.WriteLine("-Lidgren.Network Message: " + msg.ReadString());
break;
case NetIncomingMessageType.UnconnectedData:
case NetIncomingMessageType.Data:
IncomingMessage im = new IncomingMessage();
im.DecodeFrom(msg);
Manager.MessageReceived(im, Port);
OnMessageReceived(new MessageReceivedEventArgs(im));
break;
case NetIncomingMessageType.StatusChanged:
NetConnectionStatus status = (NetConnectionStatus)msg.ReadByte();
if (status == NetConnectionStatus.Disconnected)
Manager.Disconnected(msg.SenderEndpoint, Port);
else if (status == NetConnectionStatus.Connected)
Manager.Connected(msg.SenderEndpoint, Port);
break;
default:
throw new InvalidOperationException("An unhandled MessageType was received.");
}
lidgrenServer.Recycle(msg);
}
Thread.Sleep(1);
}
}