本文整理汇总了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;
}
示例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;
}
示例3: GetBytes
public byte[] GetBytes(IScsMessage message)
{
try
{
Cmd cmd = message as Cmd;
return _packer.pack(cmd).ToArray();
}
catch
{
return null;
}
}
示例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();
}
示例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));
}
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
示例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));
}
}
示例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));
}
示例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);
}
示例13: GetBytes
public byte[] GetBytes(IScsMessage message)
{
return ((SendPacket) message).Data;
}
示例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);
}
示例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);
}
}