예제 #1
0
        public void SendImage(Image img)
        {
            MsgTypeCell msgTypeCell = new MsgTypeCell(MsgType.Pic, ImageHelper.ImageToBytes(img));
            MsgCell     cell        = new MsgCell(0x000010, msgTypeCell);

            UdpLibrary.Send(cell, RemoteEp);
        }
예제 #2
0
        public void SendText(string strmsg)
        {
            byte[]      dataBytes   = Encoding.Default.GetBytes(strmsg);
            MsgTypeCell msgTypeCell = new MsgTypeCell(MsgType.TxtMsg, dataBytes);
            MsgCell     cell        = new MsgCell(0x000010, msgTypeCell);

            UdpLibrary.Send(cell, RemoteEp);
        }
예제 #3
0
        /// <summary>
        /// 继承Udp基类接收数据方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UdpLibraryReceiveData(object sender, ReceiveDataEventArgs e)
        {
            //若不适用内部封装协议则只激活接受原始数据事件
            if (!_isAxAgreement)
            {
                OnReceiveByte(e);
                return;
            }
            MsgCell cell = new MsgCell();

            cell.FromBuffer(e.Buffer);
            switch (cell.MessageId)
            {
            case (int)Command.RequestSendTextMSg:
                OnReceiveTextMsg((MsgTypeCell)cell.Data);
                break;

            case (int)Command.ResponeSendFile:
                OnResponeSendFile((ResponeTraFransfersFile)cell.Data);
                break;

            case (int)Command.ResponeSendFilePack:
                OnResponeSendFilePack((ResponeTraFransfersFile)cell.Data);
                break;

            case (int)Command.RequestCancelReceiveFile:
                OnRequestCancelReceiveFile(cell.Data.ToString());
                break;

            case (int)Command.RequestSendFile:
                OnStartRecieve((TraFransfersFileStart)cell.Data, e.RemoteIP);
                break;

            case (int)Command.RequestSendFilePack:
                OnRecieveBuffer((TraFransfersFile)cell.Data, e.RemoteIP);
                break;

            case (int)Command.RequestCancelSendFile:
                OnRequestCancelSendFile(cell.Data.ToString(), e.RemoteIP);
                break;
            }
        }
예제 #4
0
        /// <summary>
        /// 发送信息
        /// </summary>
        /// <param name="messageId">消息标识</param>
        /// <param name="data">序列化数据</param>
        /// <param name="remoteIp">远程主机IP</param>
        public void Send(int messageId, object data, IPEndPoint remoteIp)
        {
            MsgCell cell = new MsgCell(messageId, data);

            UdpLibrary.Send(cell, remoteIp);
        }