Jump to content
Site Stability Read more... ×
  • Advertisement


This topic is now archived and is closed to further replies.



This topic is 7163 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

im setting up a dos program to be the server for a game im working on, and i want to use nonblocking mode and not use windows messages to notify me of writing/reading access to the sockets because i plan to port it to linux later down the road alright, so everything else works fine, but within the infinite while loop, i have: for(int i = 1; i <= 10; i++){ //do some code } and the for loop doesn''t execute the code at all....its like it''s ignoring every single for loop in the program, but doing evetything else fine....i was wondering if this is maybe because of nonblocking not being totally set up right? and its blocking and not causing my loops to execute? thats the only thing i can think of...heres how im setting nonblocking mode for my listen socket: unsigned long Options = 1; ioctlsocket(ListenSock, FIONBIO, &Options); this is called right after i create the socket using socket()....after them calls i then bind() and listen() and go through the infinite while loop and it works fine for accepting new connectionsthis is in the infinite loop btw) FD_SET(ListenSock, &RecvFDS); select(0, &RecvFDS, &SendFDS, &ErrorFDS, &TVal); if(FD_ISSET(ListenSock, &RecvFDS)){ OpenSock = GetOpenSock(); FD_CLR(Socks[OpenSock].Socket, &Socks[OpenSock].RecvFDS); FD_CLR(Socks[OpenSock].Socket, &Socks[OpenSock].SendFDS); Socks[OpenSock].SINLen = sizeof(sockaddr_in); Socks[OpenSock].Socket = accept(ListenSock, (struct sockaddr*)&Socks[OpenSock].SIN, &Socks[OpenSock].SINLen); ioctlsocket(Socks[OpenSock].Socket, FIONBIO, &Options); FD_SET(Socks[OpenSock].Socket, &Socks[OpenSock].RecvFDS); FD_SET(Socks[OpenSock].Socket, &Socks[OpenSock].SendFDS); Socks[OpenSock].Active = TRUE; printf("Accepted: %i\n", OpenSock); } then it loops through all the active sockets using a for loop, if they are active it checks them for data to write/read, but the loop isn''t being preformed...i use the same checking process for the listensock as all the other client sockets i hope this is enough information for someone to help me with...or maybe a few of u have had this same problem thanx

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
After looking at your code, it seems that your array ''Sock'' contains a class or struct that has two fd_sets (RecvFDS and SendFDS) in it, and that you''re adding that socket to it''s own set. This is not the way the fd_sets are supposed to be used at all.

You should have only one fd_set for Recv, Send, and possibly Exceptions. Use FD_ZERO to clear each set before a call to select(), and then loop over your array ''Sock'' and use FD_SET to add them to the Recv and Send sets. Then call select() with the sets. I believe you have to FD_ZERO and reset the fd_sets before every call to select(), because the function itself changes the data in the sets in such a way that they can''t be reused.


fd_set recv, send, except;


for(int i = 0; i < numSocks; i++) {
FD_SET(Sock.Socket, &recv);
FD_SET(Sock[i].Socket, &send);
FD_SET(Sock[i].Socket, &except);

FD_SET(ListenSock, &recv);

select(0, &recv, &send, &except, &tv);

if(FD_ISSET(ListenSock, &recv)) {

for(int i = 0; i < numSocks; i++) {
if(FD_ISSET(Sock[i].Socket, &recv))
if(FD_ISSET(Sock[i].Socket, &send))
if(FD_ISSET(Sock[i].Socket, &except))

I hope to hell that looks right after I post...

- genovov

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!