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


C# IScsMessage类代码示例

本文整理汇总了C#中IScsMessage的典型用法代码示例。如果您正苦于以下问题:C# IScsMessage类的具体用法?C# IScsMessage怎么用?C# IScsMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


IScsMessage类属于命名空间,在下文中一共展示了IScsMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SerializeMessage

        protected override byte[] SerializeMessage(IScsMessage message)
        {
            var bytes = base.SerializeMessage(message);
            if (compress) bytes = CompressionManager.CompressGZip(bytes);
            if (encrypt) bytes = XXTEA.Encrypt(bytes, keys);

            return bytes;
        }
开发者ID:rajayaseelan,项目名称:mysoftsolution,代码行数:8,代码来源:CustomWireProtocol.cs

示例2: GetBytes

        public byte[] GetBytes(IScsMessage message)
        {
            //Serialize the message to a byte array
            byte[] bytes = message is ScsTextMessage ? 
                Encoding.Default.GetBytes(((ScsTextMessage)message).Text) :
                ((ScsRawDataMessage)message).MessageData;

            return bytes;
        }
开发者ID:aerzy,项目名称:OpenNos,代码行数:9,代码来源:WireProtocol.cs

示例3: GetBytes

 public byte[] GetBytes(IScsMessage message)
 {
     try
     {
         Cmd cmd = message as Cmd;
         return _packer.pack(cmd).ToArray();
     }
     catch
     {
         return null;
     }
 }
开发者ID:HowieXue,项目名称:Hospital_projs,代码行数:12,代码来源:EzWireProtocol.cs

示例4: GetBytes

 public byte[] GetBytes(IScsMessage message)
 {
     var m = message as Protocols.GpsMessage;
     List<byte> bytes = new List<byte>();
     logger.Debug("Data {0}", BitConverter.ToString(m.Data));
     if (m.Data != null)
     {
         bytes.Add(0x02);
         bytes.Add(m.Data[m.Data.Length - 2]);
         bytes.Add(m.Data[m.Data.Length - 1]);
         m.Data = bytes.ToArray();
     }
     return bytes.ToArray();
 }
开发者ID:aawee0,项目名称:GT02a_tracker_service,代码行数:14,代码来源:GallileoWireProtocol.cs

示例5: SendMessage

 public void SendMessage(IPEndPoint remote, IScsMessage msg)
 {
     try
     {
         byte[] buffer = this.WireProtocol.GetBytes(msg);
         if (buffer != null)
             _udp_peer.SendData(buffer, remote);
     }
     catch (System.Exception ex)
     {
         EzLogger.GlobalLogger.warning(string.Format("{0}{2}{1}{2}",
             ex.Message, ex.StackTrace, Environment.NewLine));
     }
 }
开发者ID:HowieXue,项目名称:Hospital_projs,代码行数:14,代码来源:EzUdpPeer.cs

示例6: GetBytes

 /// <summary>
 /// Serializes a message to a byte array to send to remote application.
 ///             This method is synchronized. So, only one thread can call it concurrently.
 /// 
 /// </summary>
 /// <param name="message">Message to be serialized</param><exception cref="T:Tera.NetworkApi.Communication.Scs.Communication.CommunicationException">Throws CommunicationException if message is bigger than maximum allowed message length.</exception>
 public byte[] GetBytes(IScsMessage message)
 {
     byte[] numArray = this.SerializeMessage(message);
     int length = numArray.Length;
     if (length > 134217728)
     {
         throw new CommunicationException("Message is too big (" + (object)length + " bytes). Max allowed length is " + (string)(object)134217728 + " bytes.");
     }
     else
     {
         byte[] buffer = new byte[length + 4];
         BinarySerializationProtocol.WriteInt32(buffer, 0, length);
         Array.Copy((Array)numArray, 0, (Array)buffer, 4, length);
         return buffer;
     }
 }
开发者ID:arkanoid1,项目名称:Temu,代码行数:22,代码来源:BinarySerializationProtocol.cs

示例7: SerializeMessage

        /// <summary>
        /// The sender of a message needs to provide a means to convert a (high-level) object into raw bytes
        /// that will be sent over the network connection.
        /// </summary>
        protected override byte[] SerializeMessage(IScsMessage message)
        {
            if (message is ScsRawDataMessage)
            {
                return (((ScsRawDataMessage)message).MessageData);
            }

            if (message is ScsTextMessage)
            {
                return Encoding.UTF8.GetBytes(((ScsTextMessage)message).Text);
            }

            if (message is ScsPingMessage)
            {
                //if the application idles, occasional ScsPingMessage(s) are being sent out
                //trying to serialize this as ScsTextMessage will throw an exception
            }

            return null;
        }
开发者ID:ChaosCom,项目名称:scs,代码行数:24,代码来源:MyWireProtocol.cs

示例8: GetBytes

        /// <summary>
        /// Serializes a message to a byte array to send to remote application.
        /// This method is synchronized. So, only one thread can call it concurrently.
        /// </summary>
        /// <param name="message">Message to be serialized</param>
        /// <exception cref="CommunicationException">Throws CommunicationException if message is bigger than maximum allowed message length.</exception>
        public byte[] GetBytes(IScsMessage message)
        {
            //Serialize the message to a byte array
            var serializedMessage = SerializeMessage(message); 
           
            //Check for message length
            var messageLength = serializedMessage.Length;
            if (messageLength > MaxMessageLength)
            {
                throw new CommunicationException("Message is too big (" + messageLength + " bytes). Max allowed length is " + MaxMessageLength + " bytes.");
            }

            //Create a byte array including the length of the message (4 bytes) and serialized message content
            var bytes = new byte[messageLength + 4];
            WriteInt32(bytes, 0, messageLength);
            Array.Copy(serializedMessage, 0, bytes, 4, messageLength);

            //Return serialized message by this protocol
            return bytes;
        }
开发者ID:BorjaSanchidrian,项目名称:scs,代码行数:26,代码来源:BinarySerializationProtocol.cs

示例9: SendMessageWithReplyAsync

        /// <summary>
        /// Send a Message and Wati for Reply
        /// </summary>
        /// <typeparam name="T">The expected Value</typeparam>
        /// <param name="msg">the message to send</param>
        /// <returns></returns>
        public static Task<IScsMessage> SendMessageWithReplyAsync(this IScsClient client, IScsMessage msg)
        {
            TaskCompletionSource<IScsMessage> tcs = new TaskCompletionSource<IScsMessage>();

            using (var requestReplyMessenger = new RequestReplyMessenger<IScsClient>(client))
            {
                requestReplyMessenger.Start(); //Start request/reply messenger

                //Send user message to the server and get response
                try {
                    var response = requestReplyMessenger.SendMessageAndWaitForResponse(msg);
                    tcs.SetResult(response);
                }
                catch (Exception ex)
                {
                    tcs.SetException(ex);
                }
            }

            return tcs.Task;
        }
开发者ID:furesoft,项目名称:scs,代码行数:27,代码来源:AsyncExtensions.cs

示例10: OnMessageReceived

        protected virtual void OnMessageReceived(IPEndPoint remote, IScsMessage msg)
        {
            EzLogger.GlobalLogger.debug(string.Format("udp message from {0}: {1}", remote, msg));

            if (MessageReceived != null)
            {
                MessageReceived(remote, new MessageEventArgs(msg));
            }
        }
开发者ID:HowieXue,项目名称:Hospital_projs,代码行数:9,代码来源:EzUdpPeer.cs

示例11: OnMessageReceived

 /// <summary>
 /// Raises MessageReceived event.
 /// 
 /// </summary>
 /// <param name="message">Received message</param>
 private void OnMessageReceived(IScsMessage message)
 {
     EventHandler<MessageEventArgs> eventHandler = this.MessageReceived;
     if (eventHandler == null)
         return;
     eventHandler((object)this, new MessageEventArgs(message));
 }
开发者ID:Koushi009,项目名称:Temu,代码行数:12,代码来源:ScsServerClient.cs

示例12: SendMessage

 /// <summary>
 /// Sends a message to the client.
 /// 
 /// </summary>
 /// <param name="message">Message to be sent</param>
 public void SendMessage(IScsMessage message)
 {
     this._communicationChannel.SendMessage(message);
 }
开发者ID:Koushi009,项目名称:Temu,代码行数:9,代码来源:ScsServerClient.cs

示例13: GetBytes

 public byte[] GetBytes(IScsMessage message)
 {
     return ((SendPacket) message).Data;
 }
开发者ID:wwhitehead,项目名称:ProjectFaolan,代码行数:4,代码来源:ConanWireProtocol.cs

示例14: SendMessage

        /// <summary>
        /// Sends a message to the server.
        /// </summary>
        /// <param name="message">Message to be sent</param>
        /// <exception cref="CommunicationStateException">Throws a CommunicationStateException if client is not connected to the server.</exception>
        public void SendMessage(IScsMessage message)
        {
            if (CommunicationState != CommunicationStates.Connected)
            {
                throw new CommunicationStateException("Client is not connected to the server.");
            }

            _communicationChannel.SendMessage(message);
        }
开发者ID:aerzy,项目名称:OpenNos,代码行数:14,代码来源:ScsClientBase.cs

示例15: SendMessageInternal

        /// <summary>
        /// Sends a message to the remote application.
        /// </summary>
        /// <param name="message">Message to be sent</param>
        protected override void SendMessageInternal(IScsMessage message)
        {
            //Send message
            var totalSent = 0;
            lock (_syncLock)
            {
                //Create a byte array from message according to current protocol
                var messageBytes = WireProtocol.GetBytes(message);
                //Send all bytes to the remote application
                while (totalSent < messageBytes.Length)
                {
                    var sent = _clientSocket.Send(messageBytes, totalSent, messageBytes.Length - totalSent, SocketFlags.None);
                    if (sent <= 0)
                    {
                        throw new CommunicationException("Message could not be sent via TCP socket. Only " + totalSent + " bytes of " + messageBytes.Length + " bytes are sent.");
                    }

                    totalSent += sent;
                }

                LastSentMessageTime = DateTime.Now;
                OnMessageSent(message);
            }
        }
开发者ID:HaKDMoDz,项目名称:eStd,代码行数:28,代码来源:TcpCommunicationChannel.cs


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