Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


Closed Thread
  Search this Thread
Old 10-20-2007, 05:59 PM   #1
LQ Newbie
Registered: Oct 2007
Posts: 4

Rep: Reputation: 0
About multiple timeout in Socket Programming

I am implementing a peer-to-peer program: When a computer A receives “get file XXX” from stdio, it broadcasts (floods) a request packet to ask others. Both Computer B and C have the file so they send back responses. Computer A pick up B and sends confirm to B. at the same time, it creates a server socket to listen to connection. After Compute B receives the confirm from A, it creates a client socket to connects to A.

I set timeouts to both request and confirm packets. If no response is received by A after timeout, A needs to flood a new request packet again. Otherwise, A cancels timeout of the request. For the same reason, if B does not connect to A, A will send a confirm to C so that C can connect to A

My Questions: How to set timeout?
a. I can use select(). But since I already put a select() with timeout parameter as NULL in a while loop to monitor stdio, request, confirm/response packets, it seems that there is no place to put other selects with timeout parameters。
b. I can use alarm(). But there is no way to know, which request/confirm of which file the alarm() is for. And if I cancle a timeout using alarm(0), other timeout using alarm() is also canceled.
c. I also thought about using fork()+ select(): But after the child process is terminated, how do I know it is terminated because of timeout or because response or connection is received? Besides, If it is terminated because of timout, In which part of program should I re-flood the request or re-send the confirm packet?

I want to solve the problem and need your help. Can any guru answer the question? Thanks
Old 10-20-2007, 06:07 PM   #2
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

Rep: Reputation: 472Reputation: 472Reputation: 472Reputation: 472Reputation: 472
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.

Discussion continues here:

Closed Thread

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 On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to set multiple timeout in Socket Programming. lisa000 Linux - Networking 1 10-20-2007 06:08 PM
a question about multiple connections in socket programming moloza Programming 7 05-22-2006 11:31 AM
Fedora 3 - PHP - Socket timeout b_whelan Linux - Software 2 09-29-2005 03:41 AM
Socket timeout (c question) alaios Programming 13 09-11-2005 12:43 PM
help!!! how can i timeout a socket connect call... ? bzImage Programming 1 03-06-2002 03:54 PM > Forums > Linux Forums > Linux - General

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