Advertisement

Checking Single TCP Sockets for Activity

Started by June 23, 2003 09:18 AM
4 comments, last by Lazzar 21 years, 7 months ago
hi there, Ist is possible to check Single TCP Sockets for activity? I am using the Libary SDL_net which has a function called SDL_CheckSocketSet() or something like that. It checks if any of the Sockets in the set has activity. I think it uses select() internaly... I coulnd't find a similar function to check one single Socket if there is a message in the buffer waiting. Is there any? Lazzar ---------------------------------------------------------- if god gave us the source code, we could change the world! [edited by - Lazzar on June 23, 2003 10:20:10 AM]
---------------------------------------------------------if god gave us the source code, we could change the world!
Never used SDL, but select() on a listening socket checks for incoming connections, select() on a client socket checks for available data and (in case you use that) select() on a non blocking connecting socket checks if the connection is established. Oh yeah, depends on read/write/exception attributes too ;p (1st and 2nd are read, while the 3rd one is write).
Advertisement
i want to check a client socket..


but but but...
int select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);

select expects a fd_set, but i just want to check one single socket.

the way i do it now is:
create empty socket set, add socket to set, check socketset, remove socket, delete socketset.

there has to be an easier method to check a blocking client socket for activity ?

Lazzar
---------------------------------------------------------if god gave us the source code, we could change the world!
It''s quite simple actually, just add your single socket to the desired FD_SET and call select().
quote:
Original post by Lazzar
the way i do it now is:
create empty socket set, add socket to set, check socketset, remove socket, delete socketset.

there has to be an easier method to check a blocking client socket for activity ?

Lazzar



beep!
thats the way i do it now

i was hoping i could clean up my code with an easier version.

but i guess there is no other way then...

thanks anyway
Lazzar

[edited by - Lazzar on June 23, 2003 4:49:09 PM]
---------------------------------------------------------if god gave us the source code, we could change the world!
Look into ioctlsocket() and the FIONREAD parameter. The function allows you to determine whether any data is available for reception on a particular socket.

________________________________________________
RapscallionGL development continues...
"Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C
________________________________________________"Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C

This topic is closed to new replies.

Advertisement