Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Software
User Name
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.


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

Rep: Reputation: 0
Question related to Socket programming

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);

Process message


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

Process message

Old 01-01-2012, 11:45 PM   #2
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

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

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 11:47 PM.


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

All times are GMT -5. The time now is 05:16 AM.

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