| | |
Recv()ing a long message
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2007
Posts: 5
Reputation:
Solved Threads: 0
Is there a way to read the long answer from server not using non-blocking sockets?
The problem is that recv blocks if server stops to send.
So, how to break from while(true) before recv() blocks? My experiments with select() failed. =(
The problem is that recv blocks if server stops to send.
C++ Syntax (Toggle Plain Text)
while(true){ n=recv(skt, buf, BUFFER_SIZE,0); if(n<=0)break; buf[n]='\0'; std::cout<<buf; }
•
•
Join Date: Apr 2007
Posts: 5
Reputation:
Solved Threads: 0
I'm using gcc 3.x on FreeBSD 6.1
I tried select in this way:
fd_set fd_cnt;
FD_ZERO(&fd_cnt);
FD_SET(skt, &fd_cnt);
while(true){
select(skt+1, &fd_cnt, NULL, NULL, 0);
if(!FD_ISSET(skt, &fd_cnt))break;
n=recv(skt, buf, BUFFER_SIZE,0);
if(n<=0)break;
buf[n]='\0';
std::cout<<buf;
}
but recv() still blocks.
I tried select in this way:
fd_set fd_cnt;
FD_ZERO(&fd_cnt);
FD_SET(skt, &fd_cnt);
while(true){
select(skt+1, &fd_cnt, NULL, NULL, 0);
if(!FD_ISSET(skt, &fd_cnt))break;
n=recv(skt, buf, BUFFER_SIZE,0);
if(n<=0)break;
buf[n]='\0';
std::cout<<buf;
}
but recv() still blocks.
•
•
•
•
Erm, you use select(), and you post some kind of attempt at using select() so we can figure out where you went wrong.
from what I know a blocking socket will be blocking. If you're not creating the socket then try making it non-blocking while you're using it and then make it blocking once you're done with your work.. not so nice to do though..
Use fcntl to make it non/blocking..
Last edited by thekashyap; Apr 17th, 2007 at 4:35 am.
•
•
Join Date: Apr 2007
Posts: 5
Reputation:
Solved Threads: 0
•
•
•
•
Wouldn't select() itself block !? If it does it anyway can't be used for this problem..
from what I know a blocking socket will be blocking. If you're not creating the socket then try making it non-blocking while you're using it and then make it blocking once you're done with your work.. not so nice to do though..
Use fcntl to make it non/blocking..
C++ Syntax (Toggle Plain Text)
if(!FD_ISSET(skt, &fd_cnt))break;
•
•
Join Date: Apr 2007
Posts: 5
Reputation:
Solved Threads: 0
found a simple solvation.
man recv really helped me out =)
so, in simple case we can bypass non-blocking sockets and select(). There is a way to tell recv() not to block by using MSG_DONTWAIT value.
thank you for assistance =)
man recv really helped me out =)
so, in simple case we can bypass non-blocking sockets and select(). There is a way to tell recv() not to block by using MSG_DONTWAIT value.
C++ Syntax (Toggle Plain Text)
while((n=recv(skt, buf, BUFFER_SIZE, MSG_DONTWAIT))>0){ buf[n]='\0'; std::cout<<buf; }
thank you for assistance =)
![]() |
Similar Threads
- cannot find server + dns error, IE (Web Browsers)
- uninstalling windows ME (Windows 95 / 98 / Me)
- Blaster Viruses- Problems with 2wire? (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: C++ programming Home Work HELP...please immediate assistance.assistance.
- Next Thread: WHat does this mean?
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph homeworkhelp iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg simple sorting spoonfeeding string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






