TCP 和 UDP 能否使用相同的端口号?
2015-12-11 15:14
507 查看
答案:可以。
参考:
http://stackoverflow.com/questions/6437383/can-tcp-and-udp-sockets-use-the-same-port
Yes, you can use the same port number for both TCP and UDP. Many protocols already do this, for example DNS works on udp/53
and tcp/53.
Technically the port pools for each protocol are completely independent, but for higher level protocols that can use either TCP or UDP it's convention that they default to the same port
number.
When writing your server, bear in mind that the sequence of events for a TCP socket is much harder than for a UDP socket, since as well as the normal
Furthermore that
that socket that you'll then have to also poll for receive events. Your server should be prepared to continue
参考:
http://stackoverflow.com/questions/6437383/can-tcp-and-udp-sockets-use-the-same-port
Yes, you can use the same port number for both TCP and UDP. Many protocols already do this, for example DNS works on udp/53
and tcp/53.
Technically the port pools for each protocol are completely independent, but for higher level protocols that can use either TCP or UDP it's convention that they default to the same port
number.
When writing your server, bear in mind that the sequence of events for a TCP socket is much harder than for a UDP socket, since as well as the normal
socketand
bindcalls you also have to
listenand
accept.
Furthermore that
acceptcall will return a new socket and it's
that socket that you'll then have to also poll for receive events. Your server should be prepared to continue
accepting connections on the original socket whilst simultaneously servicing multiple clients each of which will be triggering receive events on their own sockets.
相关文章推荐
- http://www.iconfont.cn/
- 网络应用的编程模型
- Android Asynchronous Http Client
- PHP漏洞全解(七)-HTTP响应拆分
- iOS开源项目大全(一)(整理自网络)
- 简单的网络协议介绍
- iOS开源项目大全(二)(整理自网络)
- Android网络编程---HttpURLConnection
- 处理TCP连包的一小段代码
- spring(基础十) Spring HTTP Invoker使用介绍
- 用Xutils 加载网络图片。设置Appliction
- linux使用wget下载https开头url的文件
- TCP三次握手
- weblogic.net.http.SOAPHttpsURLConnection cannot be cast to javax.net.ssl.HttpsURLConnection
- java下载网页内容和网络图片
- Caffe fine-tuning 微调网络
- Android: 详解触摸事件如何传递 - 玲音 原文 http://www.cnblogs.com/superlcr/p/3946034.html
- 服务器tcp连接timewait过多优化及详细分析
- HTTP Cookies - HTTP cookie jars HTTP cookie jars:
- 同步网络请求 类封装,包括get请求和post请求,可选择是否进行JSON解析