(如何)我可以使用ServerSocket来侦听UDP而不是TCP流量?

时间:2022-08-21 23:55:03

In my application, there's a module that uses ServerSocket to listen for incoming TCP connections. When I switched a client to use UDP, I expected to receive data anyway, but I was wrong. When I looked at the documentation, however, I couldn't find any config option to set up the socket for UDP. Do I have to use a different class?

在我的应用程序中,有一个模块使用ServerSocket来侦听传入的TCP连接。当我切换客户端使用UDP时,我希望无论如何都会收到数据,但我错了。但是,当我查看文档时,我找不到任何配置选项来设置UDP的套接字。我必须使用不同的课程吗?

1 个解决方案

#1


11  

Use DatagramSocket. For a tutorial, look here http://download.oracle.com/javase/tutorial/networking/datagrams/index.html

使用DatagramSocket。有关教程,请查看http://download.oracle.com/javase/tutorial/networking/datagrams/index.html

#1


11  

Use DatagramSocket. For a tutorial, look here http://download.oracle.com/javase/tutorial/networking/datagrams/index.html

使用DatagramSocket。有关教程,请查看http://download.oracle.com/javase/tutorial/networking/datagrams/index.html