Beispiel #1
0
        void Client_Received(Object sender, ReceivedEventArgs e)
        {
            var dhcp = new DhcpEntity();

            dhcp.Read(e.Stream, null);

            var kind = dhcp.Kind;

            WriteLog("收到:{0}", dhcp);
            switch (kind)
            {
            case DhcpMessageType.Offer:
                OnOffer(dhcp, e.UserState);
                break;

            case DhcpMessageType.Ack:
                OnAck(dhcp, e.UserState);
                break;

            case DhcpMessageType.Nak:
                OnNak(dhcp, e.UserState);
                break;

            default:
                WriteLog("未知消息:\r\n{0}", dhcp);
                break;
            }
        }
Beispiel #2
0
        /// <summary>收到数据时触发</summary>
        /// <param name="e"></param>
        protected override void OnReceive(ReceivedEventArgs e)
        {
            var dhcp = new DhcpEntity();

            dhcp.Read(e.Stream, null);

            var kind = dhcp.Kind;

            WriteLog("收到:{0} {1}", kind, e.Remote);
            var ds = (this as INetSession).Host as DhcpServer;

            var dme = new DhcpMessageEventArgs
            {
                Request   = dhcp,
                Remote    = e.Remote,
                UserState = e.UserState
            };

            OnMessage?.Invoke(this, dme);

            ds.RaiseMessage(this, dme);

            if (dme.Response != null)
            {
                var buf = dme.Response.ToArray();
                Send(buf);
            }

            base.OnReceive(e);
        }