本文整理汇总了C#中IMessage.ToByteString方法的典型用法代码示例。如果您正苦于以下问题:C# IMessage.ToByteString方法的具体用法?C# IMessage.ToByteString怎么用?C# IMessage.ToByteString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMessage
的用法示例。
在下文中一共展示了IMessage.ToByteString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetRequestEnvelope
public RequestEnvelope GetRequestEnvelope(RequestType type, IMessage message)
{
return GetRequestEnvelope(new Request()
{
RequestType = type,
RequestMessage = message.ToByteString()
});
}
示例2: SendMessage
public bool SendMessage(int type, IMessage message, bool encrypt)
{
Debug.Log("Sending server message Type={0} Encrypted={1}.", type, encrypt);
ByteString messageContent = message.ToByteString();
NetworkPacket networkPacket = new NetworkPacket();
networkPacket.Type = type;
networkPacket.Server = true;
networkPacket.Encrypted = encrypt;
if (networkPacket.Encrypted) {
Debug.Log("Encrypting message content. Size={0}", messageContent.Length);
messageContent = this.ProceedMessageEncoding(this.m_clientPublicKey, messageContent);
if (messageContent == null) {
Debug.Error("Encoded message content is invalid.");
return false;
}
}
networkPacket.Message = messageContent;
return this.SendMessage(networkPacket);
}
示例3: SendMessage
private bool SendMessage(long client, bool server, int type, IMessage message, bool encrypt)
{
if (!this.m_tcpClient.Connected) {
Debug.Error("Cannot send data through a disconnected connection.");
return false;
}
ByteString messageContent = message.ToByteString();
NetworkPacket networkPacket = new NetworkPacket();
networkPacket.Type = type;
networkPacket.Server = server;
networkPacket.ClientId = client;
networkPacket.Encrypted = encrypt;
if (networkPacket.Encrypted) {
AsymmetricKeyParameter localKeyParameter = null;
if (networkPacket.Server)
localKeyParameter = this.m_serverKey;
else if(this.m_localKeyring.ContainsKey(client))
localKeyParameter = this.m_localKeyring[client];
if (localKeyParameter == null) {
Debug.Error("Invalid key for Send. ClientId={0} Server={1}.", client, server);
return false;
}
messageContent = this.ProceedMessageEncoding(localKeyParameter, messageContent);
if (messageContent == null) {
Debug.Error("Processed message is invalid.");
return false;
}
}
networkPacket.Message = messageContent;
try {
int networkPacketSize = networkPacket.CalculateSize();
int bytesSend = this.m_tcpClient.Client.Send(networkPacket.ToByteArray());
Debug.Log("Sended {0} bytes. Network packet Size={1}.", bytesSend, networkPacketSize);
return (bytesSend == networkPacketSize);
}
catch (Exception ex) {
Debug.Exception(ex);
if(!this.m_requestedDisconnect)
this.ServerConnectionError();
return false;
}
}