简体   繁体   English

套接字连接池

[英]Socket Connection Pooling

The server is multi-threaded, Instead of creating a socket connection for each request, i want to maintain a pool of socket connections ? 服务器是多线程的,而不是为每个请求创建套接字连接,而是要维护套接字连接池? If one client has done with its work, then i want to restore the connection and use for another client, Could someone explain me how to do pool of socket connections ? 如果一个客户端完成了工作,那么我想恢复连接并用于另一个客户端,有人可以解释一下如何进行套接字连接池吗?

I have no idea what your trying to be build but if its TCP server than you should look at either one of these: 我不知道您要构建什么,但是如果它的TCP服务器比您应该看这些之一:

  • Netty 净额
  • Grizzly 灰熊
  • Mina 米娜

Most of the above handles the thread pooling and long live connections for you (I have no idea what you mean by socket pooling). 上面的大多数都为您处理线程池和长连接(我不知道您所说的套接字池是什么意思)。 I highly recommend you don't re-implement the wheel till you look at some good wheels ;). 我强烈建议您在看一些好的轮子之前不要重新安装轮子;)。

The question doesn't make sense. 这个问题没有道理。 Inbound connections are delivered to you as new sockets, by the accept() function. 入站连接通过accept()函数作为新的套接字传递给您。 You don't get any opportunity to pool them. 您没有机会汇集他们。

It's entirely up to the client and how it's coded. 这完全取决于客户端及其编码方式。 The client should open a socket, and push multiple transactions through on that socket. 客户端应打开一个套接字,并通过该套接字推送多个事务。 Not much you can do from the server to enforce this, nor do I think it's a good try to. 从服务器执行强制执行此操作的方法不多,我也不认为这是一个很好的尝试。

Regards Yusuf 问候优素福

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM