Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now


4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 xSuiCidEx   Members   


Posted 10 March 2000 - 04:15 AM

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

#2 Anonymous Poster_Anonymous Poster_*   Guests   


Posted 10 March 2000 - 01:15 PM

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

#3 genovov   Members   


Posted 10 March 2000 - 01:19 PM

Bah, that was me...

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.