Hi all, I have a few questions regarding game server main loop. For single player games, I know I could simply use fixed timesteps and update 40 times in a second. However, in game server, I wonder how it's "done".
1. Do game servers use fixed timesteps? if yes, what is the common "tick-rate"?
2. If they tick at 40 Hz, that means they will not merely update the simulation 40 times in a sec, but also do send() and recv() and accept() 40 times too right?
3. Here's my game server loop (that I can think about). Is it correct? please CMIIW
//this is just pseudo code
int main(){
long timeskip=1000/40; //40Hz simulation
init_server(); //initialization code goes here
start_server(); //server starts listening
while(running){
long time=get_time();
//fixed timestep @ 40 Hz...
while(time > lasttime){
poll_using_select(); //this will prepare socket for polling
accept_new_connection(); //server accept()
recv_on_clients(); //if there's data to be read, call recv()
simulate(timeskip/1000.0); //simulate game
send_on_client(); //send() update. But I'M AFFRAID IT WILL BLOCK!!
lasttime += timeskip;
}
}
kill_server(); //cleanup code goes here
return 0;
}
4. Is it the right choice to use select() with blocking sockets? or should I make it nonblocking no matter what? Please don't tell me to use boost::asio or epoll() or something like that. I'm still learning. I might resort to those options later, when scalability demands. But for now, I just want to use basic socket functions.
5. I know I can poll socket readiness using select(), and then recv() on it when there's data to be read. so I don't block on recv(). However, I also read that send() blocks by default, but when? isn't a socket always ready to send()?