Exemple #1
0
        private void OnReceive(IAsyncResult ar)
        {
            try
            {
                clientSocket.EndReceive(ar);

                _msgReceived = new DataMessage(data);
                isReceive    = true;
            }
            catch (ObjectDisposedException)
            { }
            catch (Exception ex)
            {
                isReceive = false;
                MessageBox.Show(ex.Message, "Receiving", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #2
0
        private void SendMessage(TypeConnect type, Mat message)
        {
            DataMessage msgToSend = new DataMessage();

            msgToSend.clientName  = this.clientName;
            msgToSend.message     = message;
            msgToSend.typeConnect = type;

            try
            {
                data = msgToSend.ToByte();
                clientSocket.BeginSendTo(data, 0, data.Length, SocketFlags.None,
                                         serverEndPoint, new AsyncCallback(OnSend), null);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Client Sending",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }