本文整理汇总了C#中PirateSpades.Network.PirateMessage.GetBytes方法的典型用法代码示例。如果您正苦于以下问题:C# PirateMessage.GetBytes方法的具体用法?C# PirateMessage.GetBytes怎么用?C# PirateMessage.GetBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PirateSpades.Network.PirateMessage
的用法示例。
在下文中一共展示了PirateMessage.GetBytes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateBroadcastInfo
/// <summary>
/// Update broadcast information.
/// </summary>
private void UpdateBroadcastInfo()
{
var msg = new PirateMessage(PirateMessageHead.Bcst, PirateMessage.ConstructHostInfo(this));
this.Broadcaster.Message = msg.GetBytes();
}
示例2: SendMessage
/// <summary>
/// Send message to a client.
/// </summary>
/// <param name="pclient">Client to send to.</param>
/// <param name="msg">Message to send.</param>
public void SendMessage(PirateClient pclient, PirateMessage msg)
{
Contract.Requires(pclient != null && msg != null);
try {
byte[] buffer = msg.GetBytes();
pclient.Socket.BeginSend(
buffer, 0, buffer.Length, SocketFlags.None, MessageSent, new PirateMessageObj(pclient, msg));
} catch(SocketException ex) {
if(!IgnoreSocketErrors.Contains(ex.SocketErrorCode)) Console.WriteLine("SocketException:" + ex);
this.SocketDisconnect(pclient);
}catch(Exception ex){
Console.WriteLine(ex);
}
}
示例3: SendMessage
/// <summary>
/// Send socket message asynchronously.
/// </summary>
/// <param name="msg">The message to send.</param>
public void SendMessage(PirateMessage msg)
{
Contract.Requires(msg != null);
var buffer = msg.GetBytes();
Socket.BeginSend(buffer, 0, buffer.Length, SocketFlags.None, MessageSent, msg);
}
示例4: KnockKnock
/// <summary>
/// Check if host is available.
/// </summary>
/// <param name="socket">The socket to communicate through.</param>
/// <returns>True if host is available, false if not.</returns>
public static bool KnockKnock(Socket socket)
{
Contract.Requires(socket != null);
var knock = new PirateMessage(PirateMessageHead.Knck, "");
socket.Send(knock.GetBytes());
var buffer = new byte[PirateMessage.BufferSize];
var read = socket.Receive(buffer);
return read > 4 && PirateMessage.GetMessages(buffer, read).Any(msg => msg.Head == PirateMessageHead.Knck);
}
示例5: PirateMessageObj
/// <summary>
/// Constructor.
/// </summary>
/// <param name="client">The client.</param>
/// <param name="msg">The message to get the byte buffer from.</param>
public PirateMessageObj(PirateClient client, PirateMessage msg)
{
Contract.Requires(client != null && msg != null);
this.Client = client;
this.Buffer = msg.GetBytes();
}