問題描述
基本上我試圖讓許多 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.
這篇關于Socket 編程 -Java - 許多客戶端一個 Socket 問題的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!