本文整理汇总了C#中Internals.Receive方法的典型用法代码示例。如果您正苦于以下问题:C# Internals.Receive方法的具体用法?C# Internals.Receive怎么用?C# Internals.Receive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Internals
的用法示例。
在下文中一共展示了Internals.Receive方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleClient
/// <summary>
/// Obsługa normalnego działania.
/// </summary>
/// <param name="client"></param>
private void HandleClient(Internals.ServerClient client)
{
if (DateTime.Now - client.LastAction > this.MaxClientIdleTime)
{
client.Send(new Message(MessageType.TimeOut, null));
client.CloseSocket();
client.Status = ClientStatus.NotResponding;
Logger.Info("Client {0}:{1} - connection closed, client is not responding", client.RemoteEndpoint.Address, client.RemoteEndpoint.Port);
}
else
{
client.Receive();
}
}
示例2: HandleWelcomeSequence
/// <summary>
/// Obsługa sekwencji powitalnej.
/// </summary>
/// <param name="client"></param>
/// <param name="i"></param>
private void HandleWelcomeSequence(Internals.ServerClient client, ref int i)
{
client.Receive();
if (client.Messages.Count > 0)
{
if (client.Messages[0].Type == MessageType.Welcome) //Odebraliśmy wiadomość powitalną
{
Messages.ClientWelcome msg;
try
{
msg = new Messages.ClientWelcome(client.Messages[0]);
}
catch //Błędna
{
client.Send(new Message(MessageType.InvalidSequence, null));
client.CloseSocket();
Logger.Info("Client {0}:{1} rejected, reason: invalid welcome sequence", client.RemoteEndpoint.Address, client.RemoteEndpoint.Port);
this._ClientsCollection.RemoveAt(i--);
return;
}
client.Messages.RemoveAt(0);
if (msg.Version == this.Version) //Wszystko ok
{
client.Send(new Message(MessageType.AllOk, null));
client.Status = ClientStatus.Ok;
Logger.Info("Client {0}:{1} - welcome sequence went well", client.RemoteEndpoint.Address, client.RemoteEndpoint.Port);
}
else //Niepoprawna wersja
{
client.Send(new Message(MessageType.IncompatibleVersion, null));
client.CloseSocket();
Logger.Info("Client {0}:{1} rejected, reason: incompatible version", client.RemoteEndpoint.Address, client.RemoteEndpoint.Port);
this._ClientsCollection.RemoveAt(i--);
}
}
else if (client.Messages[0].Type == MessageType.IncompatibleVersion ||
client.Messages[0].Type == MessageType.InvalidSequence) //Klient ma inną wersję niż my
{
client.CloseSocket();
Logger.Info("Client {0}:{1} closed the connection, reason: incompatible version", client.RemoteEndpoint.Address, client.RemoteEndpoint.Port);
this._ClientsCollection.RemoveAt(i--);
}
else //Błędna sekwencja ze strony klienta
{
client.Send(new Message(MessageType.InvalidSequence, null));
client.CloseSocket();
Logger.Info("Client {0}:{1} rejected, reason: invalid welcome sequence", client.RemoteEndpoint.Address, client.RemoteEndpoint.Port);
this._ClientsCollection.RemoveAt(i--);
}
}
}