Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socket Programming -Java - Many Clients One Socket Question(s)

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.

Thanks, Faisal Abid

like image 825
Faisal Abid Avatar asked Jun 16 '26 09:06

Faisal Abid


1 Answers

Socket is identified by following tuple,

  1. Source IP
  2. Source Port
  3. Dest IP
  4. Dest Port
  5. Protocol (TCP or UDP)

Even 1000 clients all connect to the same port (dest port), each will get its own socket. So you will have 1000 sockets open.

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.

like image 131
ZZ Coder Avatar answered Jun 18 '26 23:06

ZZ Coder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!