Java – Socket Programming – Java – A socket problem for many customers

Socket Programming – Java – A socket problem for many customers… here is a solution to the problem.

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.

Thank you
Faisal Abid

Solution

Sockets are identified by the following tuples

  1. Source IP
  2. Source port
  3. Destination IP
  4. Port of destination
  5. Protocol (TCP or UDP
  6. ).

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.

Related Problems and Solutions