C Board  

Go Back   C Board > General Programming Boards > Networking/Device Communication

Reply
 
LinkBack Thread Tools Display Modes
Old 03-27-2009, 07:43 AM   #1
Registered User
 
PING's Avatar
 
Join Date: Nov 2004
Location: india
Posts: 493
Multiple Threads, One listener.

I have a situation where I have multiple threads sending data over a socket. The intended recipients should accept the data, process it, and send it back to the original sender. I have thought of two configs. One where there is just one listening port on the sender side and this port forwards the received data to the thread which shot off the request in the first place. This requires an additional thread_id field to be sent over the network. The second would be that each thread gets its own port for sending and receiving data. This limits the number of simultaneous requests over the net. Is there some other config that I can look into? I am using unix sockets and posix threads using C / C++.

Thanks.
__________________
Go Petr !!
My Blog
PING is offline   Reply With Quote
Old 03-27-2009, 07:46 AM   #2
subminimalist
 
MK27's Avatar
 
Join Date: Jul 2008
Location: NYC
Posts: 3,944
Not that I have experience doing exactly this but I would say go with the former idea (one listener and an ID for recipient); multiple ports seems silly and implies the number of connnections is small enough to be dealt with by a single server port anyway.
__________________

Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS
MK27 is online now   Reply With Quote
Old 03-27-2009, 12:11 PM   #3
Rampaging 35 Stone Welsh
 
abachler's Avatar
 
Join Date: Apr 2007
Posts: 2,927
You will have to use a critical section to control access to the send function though, otherwise the messages may get garbled with one another. If you assign a particular thread to process a particular type of information then all incoming packets fo that type can be forwarded to teh appropriate thread, but if you have types of information that all threads can possibly have requested, then you need to have teh individual threads keep track of what information they requested and reject any pacets they didnt request, this adds overhead in that incoming packets have to be dispatched to each possible thread. I cant think off hand why you would need this complicated scheme.
__________________
He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet

Last edited by abachler; 03-27-2009 at 12:13 PM.
abachler is offline   Reply With Quote
Old 03-27-2009, 12:19 PM   #4
Senior software engineer
 
brewbuck's Avatar
 
Join Date: Mar 2007
Location: Portland, OR
Posts: 5,381
Why not give each request a unique tag (an integer). This tag gets passed back along with the response, where it can be dispatched to whichever thread allocated that tag. You could use the thread_id itself as the tag, probably.
__________________
"Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot
brewbuck is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with multiple threads Cogman Windows Programming 2 07-05-2009 09:40 AM
Multiple Threads NuNn C Programming 3 03-14-2009 11:29 PM
Question about Multiple threads and ring buffer. qingxing2005 C Programming 2 01-15-2007 12:30 AM
Race condition: getting multiple threads to cooperate FlyingDutchMan C++ Programming 10 03-31-2005 05:53 AM
Modeless Dialogs in Multiple threads MrGrieves Windows Programming 0 06-22-2004 01:33 PM


All times are GMT -6. The time now is 07:29 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22