I'm attempting my first multiplayer game (nothing complex, just a 2D shooter arena thingy), and have encountered a problem...
The server will also be displaying graphics of what's going on in the game, and is used to edit the map in real time (like that new popular flash game, Everybody Edits, yes I'm a copy cat!)
The editor itself is done, but when I add in the server functionality, the client will only process the editor's logic for a single frame after a message has been received.
Here's the code for my server. The Run function is called every loop. How do I make it so that if there's no message to do stuff with, it skips this part?
class Server{
public:
UdpSocket Socket;
unsigned short Port;
Server(unsigned short GetPort){
Port = GetPort;
Socket.Bind(Port);
}
void Run(){
char buffer[1024];
size_t received = 0;
IpAddress sender;
cout << "Waiting For Next Message" << endl;
// Get Messages
Socket.Receive(buffer, sizeof(buffer), received, sender, Port);
cout << sender.ToString() << buffer << endl;
string M = buffer;
// A Player is connecting
if (M.find("Connecting")){
// Send an answer
string message = "Accepted";
Socket.Send(message.c_str(), message.size() + 1, sender, Port);
}
}
};