是否有可能让插座保持无限时间 [英] Is it possible to keep sockets open infinite time

查看:95
本文介绍了是否有可能让插座保持无限时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是网络编程的新手。我感兴趣的是可以通过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.

推荐答案

理论上可以使服务器套接字无限期地保持打开状态;但是,使用客户端套接字不可能这样做。主要原因是因为客户端套接字依赖于处理数据的服务器端套接字,而服务器套接字可能会关闭连接。

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.

这篇关于是否有可能让插座保持无限时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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