LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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 09-09-2005, 05:08 PM   #1
dragondad
LQ Newbie
 
Registered: Aug 2005
Posts: 18

Rep: Reputation: 0
Multiple clients communicating to one socket


Is it possible to have multiple client "c" programs communicating to the same server using the same socket. If so, how does the server know which client to send a message back to.

If somebody could illustrate this in linux "C" code I would very much appreciate it.
 
Old 09-09-2005, 09:39 PM   #2
carl.waldbieser
Member
 
Registered: Jun 2005
Location: Pennsylvania
Distribution: Kubuntu
Posts: 197

Rep: Reputation: 32
Re: Multiple clients communicating to one socket

Quote:
Originally posted by dragondad
Is it possible to have multiple client "c" programs communicating to the same server using the same socket. If so, how does the server know which client to send a message back to.

If somebody could illustrate this in linux "C" code I would very much appreciate it.
There are probably several ways to do this, but in a simple scenario, the server listens to the port via accept(). When a connection arrives, the accept() call returns and you have a socket for communication with the client. You fork() a child to handle the communication, while the parent goes back to accept() another connection.

I don't have any C code on hand with an example, but I have some python code that illustrates it.
 
Old 09-09-2005, 09:40 PM   #3
zaichik
Member
 
Registered: May 2004
Location: Iowa USA
Distribution: CentOS
Posts: 419

Rep: Reputation: 30
Hi dragondad,

Since a socket equals an address plus a port, and we have to assume that the addresses for unique clients are also unique, then the server simply responds to the source address/port.

Does that answer the question, or did I not understand it correctly?
 
Old 09-10-2005, 08:22 AM   #4
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
A server will listen() on a single port. When a connection is made, the server accept()s the connection, which yields a unique file stream for that communication. You can have as many connections on a port as your server/system can cope with.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
multiple clients for echo server msriram_linux Linux - Networking 1 12-05-2007 03:27 PM
multiple-echo-clients-server msriram_linux Linux - Networking 2 12-05-2007 12:10 PM
Single Socket Vs Multiple Socket Kumar Programming 1 10-05-2005 10:02 AM
MRTG configured to serve multiple clients debloxie Linux - Networking 3 03-14-2005 11:28 AM
Multiple Clients One Authentication jpbarto Linux - Networking 4 10-02-2003 01:50 PM


All times are GMT -5. The time now is 01:32 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration