(如何)我可以使用ServerSocket来侦听UDP而不是TCP流量? [英] (How) can I use ServerSocket to listen for UDP instead of TCP traffic?

查看:183
本文介绍了(如何)我可以使用ServerSocket来侦听UDP而不是TCP流量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

推荐答案

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

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

这篇关于(如何)我可以使用ServerSocket来侦听UDP而不是TCP流量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆