LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 03-31-2010, 04:06 AM   #1
barunparichha
Member
 
Registered: Jun 2006
Location: Bangalore,india
Distribution: Linux(Redhat,fedora,suse,ubantu), Solaris (s8/s9/s10/nevada/open-solaris)
Posts: 303

Rep: Reputation: 32
blocking socket Vs non-blocking socket


My question is quite simple:
What are type of applications where socket in blocking mode can be used ?
And where non-blocking mode to be used ??


TCP is blocking by default.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 04-02-2010, 07:23 AM   #2
pantalone
LQ Newbie
 
Registered: Aug 2009
Location: Pittsboro, NC, USA
Distribution: Ubuntu
Posts: 7

Rep: Reputation: 1
"Blocking" simply means that when you call a function, it does not return until it has completed its job. "Non-blocking" means that the function returns right away, even if it was not able to complete its mission. There are good reasons to prefer one mode or another, depending on the requirements of your program.

For example, if your program is an FTP client, and you are uploading a file to an FTP server, you might use blocking mode. When you call the send() function to transfer a block of data, you want to know that when the function returns, all of that data is on its way to the server. Because your program has nothing else to do except upload the file, you don't care if it takes some amount of time before the function returns.

On the other hand, if your program is an FTP server, you might have to deal with dozens of client connections, all trying to transfer files at the same time. In that case, you might use non-blocking mode. When you call the recv() function to receive data from client A, you don't necessarily want to wait until all the data arrives, because you have other clients that need your attention. With non-blocking mode, the call to recv() will return right away, even if there was no data waiting to be received, and you can try to receive data from a different client. You can use the select() function to check each connection to see which ones have data that is ready to be received.

In short, you would probably use non-blocking mode in cases where you need to do some kind of multi-tasking and you don't want to wait if the hardware or the remote host isn't ready yet.
 
2 members found this post helpful.
Old 04-02-2010, 07:38 AM   #3
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
pantalone

Thanks for replying, I had the same question !
 
  


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
Help with non blocking udp socket mhogue Programming 2 02-04-2010 02:07 AM
Help with Non Blocking UDP Socket mhogue Programming 1 02-02-2010 05:39 PM
socket blocking problem pervert Programming 4 05-21-2006 01:28 PM
Help on socket Programming non-blocking io mounterriver Linux - Networking 3 03-21-2005 07:43 AM
C socket non-blocking bob66 Programming 1 03-13-2005 10:21 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:13 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration