-
July 6th, 2009, 01:13 PM
#1
Chat design... using sockets?
I'm trying to design a C++ chat application. I'd like it to be able to cope with any number of users (it's a theoretical problem), no matter how big this number might be.
I've been reading documentation about sockets, and, even if there are some socket based chat applications, I'm not sure of neither whether this is the best approach nor whether sockets would make my system collapse if an enormous amount of users tried to use the chat at once.
As far as I understand it, for each connecting socket a new port has to be opened. And in case the chat application allowed private conversations, it wouldn't be possible to repeat a port number, even in different processes, let alone threads... So, if I'm taking the wrong way and someone can clearly explain me why, and, even better, to hint me another option, I'd be most grateful.
Regards,
S.
-
July 14th, 2009, 05:53 AM
#2
Re: Chat design... using sockets?
Originally Posted by s.g.
...for each connecting socket a new port has to be opened... ...it wouldn't be possible to repeat a port number...
This is true. The port number is unique. Whenever the port number is in used, it can't be used by another process.
Originally Posted by s.g.
I'm trying to design a C++ chat application. I'd like it to be able to cope with any number of users.
Fortunately, you can have more than one application connecting to a port number. For instance, there are a lot of internet browsers (all over the world) connecting to this forum, which is using port 80. Notice that the forum can still works with only one port number.
Originally Posted by s.g.
...whether this is the best approach nor whether sockets would make my system collapse if an enormous amount of users tried to use the chat at once...
No matter how good you design it, there is a physical limitation for a connection. Let me explain in another way, assuming there is a server with 1MB/s for its network connection. If there are traffic more than 1MB/s to that server, no matter which port number is requested to, the server is dead.
Another concrete example is a pipe, you can only flow 1litr/s water through it. If you load in 100ltr/s, the pipe may break.
Originally Posted by s.g.
...So, if I'm taking the wrong way and someone can clearly explain me why, and, even better, to hint me another option, I'd be most grateful...
I am trying to understand your design, my guess is, you want to have a peer-to-peer application. The application can communicate to each other that allows users to talk.
First, actually, you may not need so many ports. You can use one ports and accept any connection to that port, put whatever package that you receive to a queue.
Second, you can limit your application to a certain number of concurrent connection. A thread of your application can close the port and another thread can take over the port, after a period of time (Windows limitation).
Finally, you should remember that port number is not physical. In fact, the port design in Windows is totally different from Linux. Referring to my explanation above, the limitation of your application may not be located at your application but the physical network capacity.
Hope this help.
Xander Tan
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|