コード例 #1
0
            protected override void DoSendMessage(Message msg)
            {
                // defensive programming before entering the stack, lower layers
                // should assume a correct message.
                if (msg != null)
                {
                    // check message before sending through the stack
                    if (msg.PeerAddress.Address == null)
                    {
                        throw new IOException("Remote address not specified");
                    }

                    // the ProxyCommunicator can't use the API
                    // SendMessageOverLowerLayer because it has two lower layers

                    Response response = msg as Response;
                    if (response != null)
                    {
                        Request request = response.Request;

                        if (_httpStack.IsWaitingRequest(request))
                        {
                            if (msg.IsEmptyACK)
                            {
                                // if the message is not the actual response, but
                                // only an acknowledge, should not be forwarded
                                // (HTTP is on TCP so there is no need for acks in
                                // the application layer)
                                return;
                            }

                            _httpStack.SendMessage(msg);
                            return;
                        }
                    }

                    _coapStack.SendMessage(msg);
                }
            }