Вы, вероятно, не собираетесь иметь много забавы, пишущий Ваш собственный синтаксический анализатор MIME. Причина Вы находите "чрезмерно развитые почтовые пакеты обработки", состоит в том, потому что MIME является действительно сложным набором правил/форматов/кодировки. Части MIME могут быть рекурсивными, который является частью забавы. Я думаю, что Ваш лучший выбор состоит в том, чтобы записать лучший обработчик MIME Вы, проанализировать сообщение, может выбросить все, что это не текст/плоскость или текст/HTML, и затем вынудите команду во входящей строке быть снабженной префиксом КОМАНДУ: или что-то подобное так, чтобы можно было найти его в навозе. Если Вы запускаете с правил как этот, у Вас есть достойный шанс обработки новых поставщиков, но необходимо быть готовы настроить, если новый поставщик приезжает (или heck, если текущий поставщик принимает решение изменить их архитектуру обмена сообщениями).
What port a response is assigned is up to the application. UDP is completely stateless, so after firing off a packet the only way an application can expect a response is if it knows the other end is going to send one. Depending on the UDP application, I'd expect that the response would come on the same port for simplicity -- this is not the case for protocols like TCP, which have an intentionally random (and high) source port.
To answer your second question, many routers, even inexpensive home routers, do stateful packet inspection (SPI). Something like this likely happens, but I'm up for being corrected if I'm off:
[Set stage with client, router, Internet, server.]
How this is implemented is specific to the router, I'd imagine, but that's my understanding of how it works.
If I send a message to a UDP port on another machine, whichever port I send the message from, no matter how it is selected, will appear in the UDP datagram. I would have thought that the remote end would send any response to that datagram to that source port.
I suppose the same applies even if ports are changed by firewall or NAT device, the remote end sees a datagram from a particular port and sends the reply back, the firewall/NAT device then translates that port to the original source port.
When you create the UDP socket, you must bind it to a port number. If you dont, the operating system will assign an ephemeral port.
The application on the other side must know of this port. When replies are sent back, your router might not know how to route. There are 2 ways to resolve this problem