Im trying to make a server, built it already, however, there is a problem, since its a game, well, something like that i need to execute a function for wait for user input (gets()), and a function for get new data from server (recv(sock,buffer,64,0)), and the other one will print data from game ( though its OpenGL, however it will loop in same way )
However, gets(), and recv() pauses the console, and doesnt continues the loop until user writes a command or server sends data
I need it to check if user wrote command, or if data sent by server, and that will be inside of the while() loop of the OpenGL drawing, but not possible if it pauses
I cannot use multithreading since hoping that the people play the game with just 1 core... though i already tryied multithreading and didnt work ( in 5 different ways, last was OpenMP )
Since its an OpenGL window with Console created with AllocConsole, i have to switch stdin and stdout for it print data by using cout ( if possible, tell me how to print without need of doing soo many changes )
code is like this:
Code:
void waitforCommands()
{
char bufc[256];
char command[50];
freopen("CONIN$","rb",stdin); // for be able to write
gets(command); // THIS PAUSES
strcpy(bufc,"~3");
strcat(bufc,command);
send(sock,bufc,64,0); //Send Data
bufc[0] = '\0';
command[0] = '\0';
}
void waitforMessages()
{
char buf[256];
freopen("CONOUT$","wb",stdout); // for print at console
res=recv(sock,buf,64,0); // receive data, PAUSES TOO
cout << buf;
buf[0] = '\0';
freopen("CONIN$","rb",stdin); // for write again
}
Code is executed inside of a while() when draw OpenGL scene
Probably its simple, so, if possible, can someone tell me how to do for they execute in loop? without pausing and without multithreading ( i dont think people will have about 3 cores for execute that, also, such waste, 1 core for receive, 1 for send and 1 for draw ), else if have to do with multi threading, can post code of how to? since have tryied many different ways and didnt work
Thanks by attention and if possible, answer