客户端套接字维护队列/池
我正在尝试创建客户端套接字连接,当创建新请求时,会建立连接并建立连接。发生数据传输。有什么方法可以让连接创建后就一直打开吗?如果是,那么如何创建它&另外我如何识别发送了什么请求?得到相同请求的响应吗?
期待您的回复。
I am trying to create a client socket connection, when a new request is created a connection is established & data transfer takes place. Is there any way that once the Connection is created it will be open for all time ? If yes then how can create it & also how can I identify what request is sent & got the response for the same request?
Looking forward for your response.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以一直创建连接,但不关闭它。然而,诀窍是检测连接何时失败。例如,客户端/服务器已重新启动。
如果你想将请求与响应匹配,你可以使用请求 ID,但一种更简单的方法是每个套接字一次只发送一个请求,这样你得到的响应就是你刚刚发送的请求。如果需要,您可以在一个线程中使用多个套接字。
You can create a connection for all time, by not closing it. However the trick is detecting when a connection has failed. e.g. the client/server has restarted.
If you want to match requests to responses you can use a request id, but a much simpler approach is to only send one request at a time per socket, that way the response you get is for the request you just sent. You can use more than one socket in a thread if this is required.