/// <summary> /// </summary> /// <param name="asyncResult"> /// </param> public void ReadCallBack(IAsyncResult asyncResult) { lock (this.streamLockRead) { try { NetworkStream network = this.clientSocket.GetStream(); int read = network.EndRead(asyncResult); if (read == 0) { network.Close(); this.clientSocket.Close(); this.OnDisconnect(); return; } MemoryStream memoryStream = new MemoryStream(asyncResult.AsyncState as byte[]); MessagePackSerializer <OnMessageArgs> messagePackSerializer = MessagePackSerializer.Create <OnMessageArgs>(); OnMessageArgs args = messagePackSerializer.Unpack(memoryStream); this.MessageReceived(this, args); } catch (Exception e) { LogUtil.ErrorException(e); return; } } this.WaitForRequest(); }
/// <summary> /// </summary> /// <param name="request"> /// </param> /// <param name="ID"> /// </param> /// <param name="data"> /// </param> public static void SendReply(HandleClientRequest request, byte ID, byte[] data) { OnMessageArgs args = new OnMessageArgs(); args.ID = ID; args.Data = data; request.SendData(args); }
/// <summary> /// </summary> /// <param name="ID"> /// </param> /// <param name="data"> /// </param> public static void SendMessage(byte ID, byte[] data) { OnMessageArgs args = new OnMessageArgs(); args.ID = ID; args.Data = data; client.SendData(args); }
/// <summary> /// </summary> /// <param name="arg"> /// </param> public void SendData(OnMessageArgs arg) { lock (this.streamLockWrite) { MessagePackSerializer <OnMessageArgs> messagePackSerializer = MessagePackSerializer.Create <OnMessageArgs>(); byte[] buffer = messagePackSerializer.PackSingleObject(arg); NetworkStream serStream = this.clientSocket.GetStream(); serStream.Write(buffer, 0, buffer.Length); serStream.Flush(); } }
/// <summary> /// </summary> /// <param name="args"> /// </param> /// <exception cref="NullReferenceException"> /// </exception> public void SendData(OnMessageArgs args) { lock (this.streamLockWrite) { MessagePackSerializer <OnMessageArgs> messagePackSerializer = MessagePackSerializer.Create <OnMessageArgs>(); byte[] data = messagePackSerializer.PackSingleObject(args); if (this.networkStream == null) { throw new NullReferenceException("Network stream gone away!"); } if (this.networkStream.CanWrite) { this.networkStream.Write(data, 0, data.Length); this.networkStream.Flush(); } } }
/// <summary> /// </summary> /// <param name="onMessageArgs"> /// </param> private static void ClientMessageReceived(object sender, OnMessageArgs onMessageArgs) { ReceivedMessageFromServer(sender, onMessageArgs); }
/// <summary> /// </summary> /// <param name="request"> /// </param> /// <param name="onMessageArgs"> /// </param> private static void server_MessageReceived(HandleClientRequest request, OnMessageArgs onMessageArgs) { ReceivedMessageFromClient(request, onMessageArgs); }
/// <summary> /// </summary> /// <param name="onMessageArgs"> /// </param> private static void client_MessageReceived(OnMessageArgs onMessageArgs) { ReceivedMessageFromServer(onMessageArgs); }
/// <summary> /// </summary> /// <param name="request"> /// </param> /// <param name="onMessageArgs"> /// </param> private static void ServerMessageReceived(object sender, OnMessageArgs e) { ReceivedMessageFromClient((HandleClientRequest)sender, e); }
/// <summary> /// </summary> /// <param name="args"> /// </param> /// <exception cref="NullReferenceException"> /// </exception> public void SendData(OnMessageArgs args) { lock (this.streamLockWrite) { MessagePackSerializer<OnMessageArgs> messagePackSerializer = MessagePackSerializer.Create<OnMessageArgs>(); byte[] data = messagePackSerializer.PackSingleObject(args); if (this.networkStream == null) { throw new NullReferenceException("Network stream gone away!"); } if (this.networkStream.CanWrite) { this.networkStream.Write(data, 0, data.Length); this.networkStream.Flush(); } } }
/// <summary> /// </summary> /// <param name="arg"> /// </param> public void SendData(OnMessageArgs arg) { lock (this.streamLockWrite) { MessagePackSerializer<OnMessageArgs> messagePackSerializer = MessagePackSerializer.Create<OnMessageArgs>(); byte[] buffer = messagePackSerializer.PackSingleObject(arg); NetworkStream serStream = this.clientSocket.GetStream(); serStream.Write(buffer, 0, buffer.Length); serStream.Flush(); } }