views:

583

answers:

5

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

+2  A: 

First of all, are sockets meant for many(1000+) clients connecting to one socket (say port 2202) on one server

Yes, your server will open a socket on port 2202, and 1000 client will connect to it. Server open server socket, and client will open client socket, it different.

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

On server, you use getInputStream function to get data from client, and getOutputStream function to send data to Client.

Notice: you should use Thread to process each request of client

misamap
When i send data to client(s) does it send it to one particular client, or every client?
Faisal Abid
It depend on your demand, if you config send to all, it will send to all. If you want to send data to specified client, it will sent to that client.
misamap
+4  A: 

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.

ZZ Coder
+1  A: 

There is nothing wrong with many socket clients that use blocking I/O (you may have a look at this article for more information about that). However, there are another approaches that can better fit your needs here:

denis.zhdanov
A: 

Hi connecting with 1000 clients at the same time using simple java socket programming is not the perfect way. The probelm is that in fedora linux default maximum no of file can be open is 1024 and in windows it is 2048 or something like that. so in your server side you will find more than 1000 files open and after that if client will go on increaing then you will find too many files opnened error. so the better way is to use non blocking socket programming (I mean to say to use SocketChannel) Using socket channel at the same time as per i have check we can connect with 20,000 clients without any problem.

So better use nio. there is a very good book from Oreilly publication for java nio. I have used java nio (socket channel)

Thanks Sunil Kumar Sahoo

Deepak
Thanks Sunil, i will take a look.
Faisal Abid
A: 

Hi, i am using Linux fedora 2.6.by using server client (socket) programming ,the LISTEN system call how many connections server accept(default :how many clients) once.

Regrds venkat

venkat
Please re-post this as a question by clicking the 'Ask Question' button at the top of the page. This section is specifically for answers to this question.
Alex JL