Sockets questions :?
Hmmm, i''ve got a problem, when i try to recieve using the recv function, the socket hangs there unstill it recieves something and in consecuence hangs my program, i could use threads to avoid this but, is there any other way arround this?
Thanks.
Lookup nonblocking threads. That means that if there is no data when you call the recv function it keeps going on through your code. You are currently using blocking sockets, which means that the code will wait on the recv until it gets something.
~Graham
----
while (your_engine >= my_engine)
my_engine++;
~Graham
----
while (your_engine >= my_engine)
my_engine++;
----
Senior Rendering Engineer @ Frostbite
Previously at BioWare
Author of Game Engine Toolset Development
http://www.frostbite.com/2016/03/optimizing-the-graphics-pipeline-with-compute/
http://blog.bioware.com/2013/07/25/staff-blog-graham-wihlidal-senior-software-engineer/
January 02, 2004 03:31 PM
quote:
Original post by gwihlidal
Lookup nonblocking threads
You mean sockets right?
Ya, I''m a little tired =)
"Nonblocking sockets"
~Graham
----
while (your_engine >= my_engine)
my_engine++;
"Nonblocking sockets"
~Graham
----
while (your_engine >= my_engine)
my_engine++;
----
Senior Rendering Engineer @ Frostbite
Previously at BioWare
Author of Game Engine Toolset Development
http://www.frostbite.com/2016/03/optimizing-the-graphics-pipeline-with-compute/
http://blog.bioware.com/2013/07/25/staff-blog-graham-wihlidal-senior-software-engineer/
or you could check the socket for activity and only read from the Socket when there is activity.
if theres nothing you dont call recv().
i used it that way in SDL_net, not sure if it works in your project of course.
Lazzar
---------------------------------------------------------
if god gave us the source code, we could change the world!
if theres nothing you dont call recv().
i used it that way in SDL_net, not sure if it works in your project of course.
Lazzar
---------------------------------------------------------
if god gave us the source code, we could change the world!
---------------------------------------------------------if god gave us the source code, we could change the world!
Another option you can use (assuming your using Windows, not sure about other platforms) is asynchronous sockets. With this, you register a message for Windows to send you every time there is data for you to recieve. This way, you can go on with your normal code, and recieve the data only when it''s there.
January 04, 2004 04:01 PM
if you''re using linux then look into fcntl() to set the socket in a non-blocking state then simply use select() to check it.
- Damage Inc.
- Damage Inc.
quote:
Original post by Anonymous Poster
if you''re using linux then look into fcntl() to set the socket in a non-blocking state then simply use select() to check it.
- Damage Inc.
i''m using that method in windows, its just called another name
ioctlsocket, look that one up in msdn and google for select and you should get going, working fine for me at least.
could share a bit from my socket-class
bool CSocket::setBlocking(SOCKET& socktoset,bool isblocking /* = true */)
{
unsigned long* arg = new unsigned long;
*arg = (int)!isblocking;
if(ioctlsocket(socktoset,FIONBIO,arg) == 0) //zero = successfull
{
yay, we''ve got a nonblocking socket
}
else
{
crap, didn''t work
}
}
reality is only an option
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement