简体   繁体   English

发送和接收相同类别的UDP数据包

[英]Sending and receiving UDP packets in the same class

I know that this is poor practice, but would it be possible to do the following? 我知道这是不好的做法,但是可以执行以下操作吗?

Send packet1 to UDP port 1
port 1 receives packet1 and sends it to port 2
port 2 receives packet2 and sends it to port 3

I don't see how i could set this up, as port 2 and port 3 would already have to be listening, waiting in a while (true) loop. 我看不到如何设置此端口,因为端口2和端口3已经必须监听,并等待while (true)循环。

port 2 and port 3 would already have to be listening 端口2和端口3必须已经在侦听

Correct 正确

waiting in a while (true) loop. 等待一会儿(true)循环。

Incorrect. 不正确。 You would have had to create the DatagramSockets , but you don't currently have to be receiving them when you send to their ports. 您将不得不创建 DatagramSockets ,但是当您发送到它们的端口时,当前不必接收它们。

However it is certainly best to do so. 但是,当然最好是这样做。 There's nothing stopping you starting separate receiving threads for all three ports, is there? 没有什么可以阻止您为所有三个端口启动单独的接收线程的,是吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM