LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-20-2008, 02:24 AM   #1
sweetytweety
LQ Newbie
 
Registered: May 2008
Posts: 17

Rep: Reputation: 0
multiclient communicaion


hi,
i ve done a multiclient socket program in which n of clients can communicte to server(client send and receive message from server).what i what is i need two clients should communicate through the server. How to do that?
 
Old 05-20-2008, 02:30 AM   #2
MS3FGX
LQ Guru
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852

Rep: Reputation: 361Reputation: 361Reputation: 361Reputation: 361
Perhaps this would be better in Programming?
 
Old 05-20-2008, 04:38 AM   #3
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
I'm working on such a program myself right now -- learning C++ that way -- and am halfway there..basically your server should listen to the sockets and when something comes out from one of them, it should send it to the rest of the sockets, right?
 
Old 05-20-2008, 01:21 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Moved: This thread is more suitable in <PROGRAMMING> and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 05-20-2008, 01:54 PM   #5
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
An HTTP server, among many other examples, provides the essence of your objective. Perhaps studying the code from one of the several 'mini web servers' would be instructive. Beej's Guide to Network Programming should also be helpful.
The general solution to the problem is that on receipt of a new connection, a child process is forked, and the child handles all communication with that specific client connection until the connection closes.
--- rod.
 
Old 05-20-2008, 11:35 PM   #6
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
I think that the original question is misunderstood. My guess is that sweetysweety looks for a way to let 2 clients communicate with each other through the server.

If so:

In the simplest scenario, the server will send received messages to all clients. In that case I would let the server keep track of all open client sockets (store in an e.g array). When data is received, you can iterate through the array and send the data to the sockets in that array.

It becomes a bit more complex if you only want to communicate between a variable number of clients. In that case the server has to keep track of the client sockets that are 'linked'. I will probably store the 'linked' sockets in an array of structs (containing two sockets). When data is received, the server will iterate through the array to find the 'linked' sockets and send the data to those sockets.
 
Old 05-21-2008, 09:41 AM   #7
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Wim, I think you may be right. I see a couple of devilish details to cope with in the objective. How does one manage connections where the desired client peer has not yet connected? Do you need to relay connection management data to each client (eg: what, if any, other clients are connected)? How do you interleave data received concurrently from multiple clients (assuming all clients get copies of data sent from other clients)? Does the server need to distribute 'channel' directory info if there is a possibility for peers to communicate in distinct groups?
It seems to me that the most well known model for this sort of communication would be an IRC server. Although I don't normally use those much at all, I believe they do what you are suggesting. Are the servers for those generally available in open-source format?
Overall, an intriguing application. I hope someone can post a definitive example of how this might be done.
--- rod.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiclient Java Socket Question Chryzmo Programming 1 04-05-2008 12:00 PM
A good ICQ/multiclient Messenger kazuni Linux - Software 15 06-05-2003 04:30 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration