Is it possible to keep sockets open infinite time(是否可以无限期保持套接字打开)
问题描述
我是网络编程新手.我很感兴趣是否可以通过 Java 服务器和 C 客户端之间的套接字建立网络连接并保持连接无限打开?我想保持连接打开以在客户端之间交换 XML 数据.
I'm new to network programming. I'm interested is it possible to establish network connection via sockets between Java server and C client and keep the connection open infinitely? I want to keep the connection open to exchange XML data between the clients.
推荐答案
理论上可以无限期地保持服务器套接字打开;但是,客户端套接字不能这样做.主要原因是客户端socket依赖于服务端socket处理数据,而服务端socket可能会关闭连接.
Is is theoretically possible to keep server sockets open an indefinitely long amount of time; however, it is not possible to do so with the client-side socket. The main reason why is because the client side socket is dependent on the server side socket handling the data, and the server socket may close the connection.
虽然可以无限期地保持连接打开,但实际方面通常会确保此类套接字不会永远保持打开状态.网络中断、中间路由器配置错误、带宽耗尽、计算能力不足等,所有这些都共同确保点对点连接充其量只是暂时的.
While it might be possible to keep a connection open indefinitely, practical aspects typically ensure that such sockets don't stay open forever. Network outages, misconfiguration in intermediate routers, exhaustion of bandwidth, lack of computing power, etc. all collude to ensure that point to point connections are at best temporary.
请注意,服务器端套接字是一个接收连接请求的套接字(产生具有自己的返回套接字的连接),因此即使没有连接也可以打开它.如果您将套接字视为与另一台计算机的开放连接,则需要重新调整思路,让服务器套接字有意义.
Note that a server side socket is a socket that receives requests to connect (spawning off connections which have their own return sockets), so it can be open even when there are no connections. If you think of a socket as an open connection to another computer, you will need to reorient your thinking to have server sockets make any sense.
这篇关于是否可以无限期保持套接字打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:是否可以无限期保持套接字打开
- 如何使用WebFilter实现授权头检查 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01