LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 01-01-2012, 09:42 PM   #1
Mushabbar
LQ Newbie
 
Registered: Mar 2011
Posts: 8

Rep: Reputation: 0
Question related to Socket programming


Hi,
This is about a multi Client server design.
Can 2 threads listen on the server socket at the same time?
Lets say server socket = fd_server_sock

Thread Func1()
{
int fd_connect = accept(fd_server_sock, (sockaddr*)&client_adresse, &len);
---

Receive();
Process message
Send();
---
---

}

Thread Func2()
{
int fd_connect = accept(fd_server_sock, (sockaddr*)&client_adresse, &len);
---

Receive();
Process message
Send();
---
---
}

Thanks,
Hussain
 
Old 01-01-2012, 10:45 PM   #2
gary185
Member
 
Registered: Jul 2011
Posts: 113

Rep: Reputation: Disabled
i don't think that will work
the standard way is to go into a loop like

while(true){
if((*fdconnect = accept(fd_server_sock, (sockaddr*)&client_adresse, &len))!= -1){
pthread_create(&thread_id,0,&SocketHandler, (void*)fdconnect );
pthread_detach(thread_id);
}
}

then in the new thread you handle the request and the listen continues on ready to spin off another thread

void* SocketHandler(void* lp){
int *fdconnect = (int*)lp;
}

there are most likely serious errors in what i have here but you can get the idea
since the file descriptor to answer the request doesn't actually handle the transaction
no need to multithread that i don't think

i guess you could theoretically bind more than one socket to the same address and have a mutlithreaded listen ?
you would definitely have to use two different sockets for that i think.
i've never tried that before

Last edited by gary185; 01-01-2012 at 10:47 PM.
 
  


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
Linux socket programming question mjp053000 Linux - Networking 3 09-16-2010 12:31 PM
Question related to programming. ArthurHuang Programming 6 05-24-2006 08:53 AM
Socket programming question brianvdc Programming 2 12-30-2004 01:36 PM
Socket Programming Question? sharma_deepak83 Programming 1 06-29-2004 10:36 AM
socket programming question.. concoran Programming 4 01-14-2002 02:23 AM


All times are GMT -5. The time now is 10:44 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