Socket Programming – Java – A socket problem for many customers
Essentially, I’m trying to get many java clients to connect to sockets (using socket gateways) on my ColdFusion server. However, before I started writing code, I was a bit confused about sockets and their performance. First, does a socket mean that many (more than 1000) clients connect to a socket on a single server (such as port 2202)? What if what is waiting is basically just a ping, or if when these clients receive this “ping” they can go and get some new data.
Sockets are identified by the following tuples
- Source IP
- Source port
- Destination IP
- Port of destination
- Protocol (TCP or UDP
Even if 1000 clients all connect to the same port (destination port), each client gets its own socket. Therefore, you will open 1000 sockets.
Maintaining 1000 sockets with blocking I/O will be difficult, which usually means 1000 threads. You need to use NIO. We have a server written in Mina that can handle 2000 connections at peak.