示例#1
0
        /// <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();
        }
示例#2
0
        /// <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);
        }
示例#3
0
        /// <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);
        }
示例#4
0
        /// <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();
            }
        }
示例#5
0
        /// <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();
                }
            }
        }
示例#6
0
 /// <summary>
 /// </summary>
 /// <param name="onMessageArgs">
 /// </param>
 private static void ClientMessageReceived(object sender, OnMessageArgs onMessageArgs)
 {
     ReceivedMessageFromServer(sender, onMessageArgs);
 }
示例#7
0
 /// <summary>
 /// </summary>
 /// <param name="request">
 /// </param>
 /// <param name="onMessageArgs">
 /// </param>
 private static void server_MessageReceived(HandleClientRequest request, OnMessageArgs onMessageArgs)
 {
     ReceivedMessageFromClient(request, onMessageArgs);
 }
示例#8
0
 /// <summary>
 /// </summary>
 /// <param name="onMessageArgs">
 /// </param>
 private static void client_MessageReceived(OnMessageArgs onMessageArgs)
 {
     ReceivedMessageFromServer(onMessageArgs);
 }
示例#9
0
 /// <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);
 }
示例#10
0
 /// <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);
 }
示例#11
0
 /// <summary>
 /// </summary>
 /// <param name="request">
 /// </param>
 /// <param name="onMessageArgs">
 /// </param>
 private static void ServerMessageReceived(object sender, OnMessageArgs e)
 {
     ReceivedMessageFromClient((HandleClientRequest)sender, e);
 }
示例#12
0
 /// <summary>
 /// </summary>
 /// <param name="onMessageArgs">
 /// </param>
 private static void ClientMessageReceived(object sender, OnMessageArgs onMessageArgs)
 {
     ReceivedMessageFromServer(sender, onMessageArgs);
 }
        /// <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();
                }
            }
        }
示例#14
0
 /// <summary>
 /// </summary>
 /// <param name="request">
 /// </param>
 /// <param name="onMessageArgs">
 /// </param>
 private static void ServerMessageReceived(object sender, OnMessageArgs e)
 {
     ReceivedMessageFromClient((HandleClientRequest)sender, e);
 }
示例#15
0
 /// <summary>
 /// </summary>
 /// <param name="request">
 /// </param>
 /// <param name="onMessageArgs">
 /// </param>
 private static void server_MessageReceived(HandleClientRequest request, OnMessageArgs onMessageArgs)
 {
     ReceivedMessageFromClient(request, onMessageArgs);
 }
示例#16
0
 /// <summary>
 /// </summary>
 /// <param name="onMessageArgs">
 /// </param>
 private static void client_MessageReceived(OnMessageArgs onMessageArgs)
 {
     ReceivedMessageFromServer(onMessageArgs);
 }
        /// <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();
            }
        }