Socket 编程 -Java - 许多客户端一个 Socket 问题
基本上我试图让许多 java 客户端连接到我的 ColdFusion 服务器上的套接字(使用套接字网关).然而,在我开始编写代码之前,我对套接字及其性能有点困惑.首先,套接字是否意味着许多(1000+)客户端连接到一台服务器上的一个套接字(比如端口 2202)?如果所有等待的基本上是一个 ping,或者当这些客户端收到这个ping"时,他们可以获取一些新数据,那么性能如何.
Essentially Im trying to get many many java clients connect to a socket on my ColdFusion server (Using the Socket Gateway). However before i even start to code this, Im a little confused about sockets and their performance. First of all, are sockets meant for many(1000+) clients connecting to one socket (say port 2202) on one server? How is the performance if all there waiting for is basically a ping, or something such that when these clients receive this "ping" they can go get some new data.
谢谢,费萨尔·阿比德
推荐答案
socket通过以下元组标识,
Socket is identified by following tuple,
- 来源 IP
- 源端口
- 目标 IP
- 目的港
- 协议(TCP 或 UDP)
即使 1000 个客户端都连接到同一个端口(目标端口),每个客户端都会获得自己的套接字.所以你将打开 1000 个套接字.
Even 1000 clients all connect to the same port (dest port), each will get its own socket. So you will have 1000 sockets open.
使用阻塞 I/O 维护 1000 个套接字将很困难,这通常意味着 1000 个线程.你需要使用蔚来.我们有一个用 Mina 编写的服务器,峰值可以处理 2000 个连接.
It's going to be tough to maintain 1000 sockets with blocking I/O, which usually means 1000 threads. You need to use NIO. We have a server written with Mina, which can handle 2000 connections at peak.
相关文章