Esempio n. 1
0
        private void NetSendData(string str, bool acsii)
        {
            UDPPacketBuffer buffer = null;

            if (acsii)
            {
                buffer = new UDPPacketBuffer(Encoding.ASCII.GetBytes(str), EndPoint);
            }
            else
            {
                byte[] Hex = funs.HexString2Bytes(str);
                buffer = new UDPPacketBuffer(Hex, EndPoint);
            }

            SendConter           += buffer.DataLength;
            label_SendCouter.Text = "S:" + SendConter.ToString();

            xServer.AsyncBeginSend(buffer);
        }
Esempio n. 2
0
        public void AsyncBeginReceive()
        {
            // this method actually kicks off the async read on the socket.
            // we aquire a reader lock here to ensure that no other thread
            // is trying to set shutdownFlag and close the socket.
            rwLock.AcquireReaderLock(-1);

            if (!shutdownFlag)
            {
                // increment the count of pending operations
                Interlocked.Increment(ref rwOperationCount);

                // allocate a packet buffer
                UDPPacketBuffer buf = new UDPPacketBuffer();

                try
                {
                    // kick off an async read
                    udpSocket.BeginReceiveFrom(
                        buf.Data,
                        0,
                        UDPPacketBuffer.BUFFER_SIZE,
                        SocketFlags.None,
                        ref buf.RemoteEndPoint,
                        new AsyncCallback(AsyncEndReceive),
                        buf);
                }
                catch (SocketException se)
                {
                    // something bad happened
                    System.Diagnostics.EventLog.WriteEntry(ServiceName,
                                                           "A SocketException occurred in UDPServer.AsyncBeginReceive():\n\n" + se.Message,
                                                           System.Diagnostics.EventLogEntryType.Error);

                    // an error occurred, therefore the operation is void. Decrement the reference count.
                    Interlocked.Decrement(ref rwOperationCount);
                }
            }

            // we're done with the socket for now, release the reader lock.
            rwLock.ReleaseReaderLock();
        }
Esempio n. 3
0
        public void setRfData(object Data)
        {
            UDPPacketBuffer RfData = (UDPPacketBuffer)Data;

            switch (RfData.Data[10])
            {
            case (0xC0):
            {
                Rf.ControlDisView(label, textBox, comboBox);
                Rf.ParseConfigFile(label, textBox, comboBox, Language);
                Rf.RfConfigDataParse(textBox, comboBox, RfData.Data);
                Rf.Show(textBox, comboBox, Language, _Netdata.Version);
                try
                {
                    int mode = (ntohs(_Netdata.MTU) >> 12) & 0x07;
                    if (Rf.GetClass() == 2)
                    {
                        if (mode > 1)
                        {
                            mode -= 1;
                        }
                    }
                    RF_C0.SelectedIndex = mode;
                }
                catch (Exception)
                {
                }
            }
            break;

            case (0xC3):
            {
                if (Rf.GetVersion(RfData.Data) != -1)
                {
                    button3.Enabled = true;
                    button4.Enabled = true;
                }
            }
            break;
            }
        }
Esempio n. 4
0
        protected override void PacketReceived(UDPPacketBuffer buffer)
        {
            TCmdHead xCmd = new TCmdHead();

            xCmd = (TCmdHead)funs.ByteToStruct(buffer.Data, xCmd.GetType());
            switch (xCmd.cmd)
            {
            case 0x04FD:
            {
                UIForm._doAddRfData(buffer);
                if (UIForm.flag == false)
                {
                    UIForm.flag = true;
                }
            }
            break;

            default:
                break;
            }
        }
Esempio n. 5
0
 protected override void PacketSent(UDPPacketBuffer buffer, int bytesSent)
 {
 }
Esempio n. 6
0
 public void _doAddRfData(UDPPacketBuffer RfData)
 {
     _syncContext.Post(setRfData, RfData);
 }
Esempio n. 7
0
 protected abstract void PacketSent(UDPPacketBuffer buffer, int bytesSent);
Esempio n. 8
0
 // these abstract methods must be implemented in a derived class to actually do
 // something with the packets that are sent and received.
 protected abstract void PacketReceived(UDPPacketBuffer buffer);
Esempio n. 9
0
        private void NetRecvData(object data)
        {
            UDPPacketBuffer buff = (UDPPacketBuffer)data;

            TextBox_Rev(buff.Data, buff.DataLength);
        }
Esempio n. 10
0
 public void _NetRecvData(UDPPacketBuffer Data)
 {
     _syncContext.Post(NetRecvData, Data);
 }
Esempio n. 11
0
        protected override void PacketReceived(UDPPacketBuffer buffer)
        {
            TCmdHead     xCmd        = new TCmdHead();
            IWin32Window win32Window = UIForm;

            xCmd = (TCmdHead)funs.ByteToStruct(buffer.Data, xCmd.GetType());
            int len = Marshal.SizeOf(xCmd);

            switch (xCmd.cmd)
            {
            case 0x00FD:    //查询返回指令
            {
                netdata_ex_new _data;
                netdata_new    xcfg    = new netdata_new();
                byte[]         newdata = funs.SubByte(buffer.Data, len, buffer.DataLength - len);
                xcfg.xdata     = (netdata)funs.ByteToStruct(newdata, xcfg.xdata.GetType());
                UIForm._curMac = funs.Byte2Mac(xCmd.mac);
                IPEndPoint Ip = (IPEndPoint)buffer.RemoteEndPoint;
                xcfg.IP         = Ip.Address.GetAddressBytes();
                xcfg.ipEndPoint = Ip;
                _data.xCmd      = xCmd;
                _data.xdata     = xcfg;
                UIForm._doAddItem(_data);
            }
            break;

            case 0x01FD:
            {
                udpclient.send(funs.Byte2Mac(xCmd.mac), 0x03fe);
            }
            break;

            case 0x02FD:
            {
                string sMac = funs.Byte2Mac(xCmd.mac);
                MessageBox.Show(win32Window, translate.getInfo("form1", "cmd_result_mac"));
            }
            break;

            case 0x03FD:
            {
                if (UIForm.flag == 1)
                {
                    UIForm._doClearList(1);
                    udpclient.send(Encoding.Default.GetBytes("www.cdebyte.comwww.cdebyte.com"));
                    flag = false;
                    MessageBox.Show(win32Window, translate.getInfo("form1", "cmd_result_cfg"));
                    UIForm._doPatchUI(2000);
                }
                if (UIForm.flag == 2)
                {
                    MessageBox.Show(win32Window, translate.getInfo("form1", "cmd_result_reboot"));
                }
                UIForm.flag = 0;
            }
            break;

            default:
                break;
            }
        }