当前位置: 首页>>代码示例>>C#>>正文


C# IMessage.ToByteString方法代码示例

本文整理汇总了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()
            });

        }
开发者ID:ChainsawPolice,项目名称:HaxtonBot,代码行数:9,代码来源:RequestBuilder.cs

示例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);
    }
开发者ID:TomiCode,项目名称:TeamNote,代码行数:22,代码来源:NetworkClient.cs

示例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;
      }
    }
开发者ID:TomiCode,项目名称:TeamNote,代码行数:52,代码来源:LocalClient.cs


注:本文中的IMessage.ToByteString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。