Cool, thanks for the help guys...
I've come up with this general idea for handling everything. In games, the way they are generally setup is to perform the same tight loop over and over. Being something along the lines of:
Code:
//Pseudo
Loop While Running
{
GetInputFromUser();
UpdateVariables();
RenderScene();
}
Perhaps slightly more complicated
So, I've decided to go in the Win32 direction with this project of mine and incorporate a similar loop:
Code:
In Main.cpp
while(MainWindow.bRunning == true)
{
MainWindow.MessageTick();
MyWinsock.LoopTick();
}
Pretty fancy eh? MainWindow is my class created for handling, you guess it, the window. And MyWinsock handles all Winsock related issues. Here are the "Ticks":
Code:
MessageTick()
void cWindow::MessageTick(void)
{
MSG Msg;
SetFocus(hWnd); //Set Focus on the Main Window
if(PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE) != 0) //DO WE HAVE ANY MESSAGES WAITING
{
TranslateMessage(&Msg); //CONVERT OUR VIRTUAL-KEY MESSAGE INTO A CHARACTER MESSAGE
DispatchMessage(&Msg); //SEND THE MESSAGE TO OUR MISC. MESSAGE HANDLER
}
else
{
//THERE WAS NO MESSAGE
//
//UPDATE THE WINDOW
UpdateWindow(hWnd);
}
}
Code:
LoopTick()
void cWinsock::LoopTick(void)
{
/*
PingExistingConnections(); //Closes any useless connections
CheckForNewConnections(); //Accept any new connections
ReceiveMessages(); //Interpret Incoming Data
*/
}
Now, the order of those may be shuffled around a bit depending on the time that it'll take/how important they end up being (I'm relatively new with this, so I'm not sure yet). And of course, more functions may be added.
I guess my biggest question right now would be, since accept() is such a jerk and causes the machine to hang if there are no incoming connections, is there a way, kind of how like PeekMessage() tells me if a message is waiting, to check quickly whether or not there is an incoming connection waiting?
My whole plan here is relying on there actually being such a function. I sure hope somebody can shed some light here...