Time Wizard: You only need one socket per connection to a unique IP. Also, if you don't have anything like SocketHasData(), that's bad. Because, you need to check to see IF there's any data before trying to grab it. Otherwise, it'll crash, and that's bad.
Also! I recommend you send ALL your packets as strings rather than ints, especially if you're planning to use strings anywhere else with netcode.
void GamePlayLoop()
{
// set to Hooktimer
if(Turn == ThisComputer)
{
// Packet: MOUSE x y left_button right_button
MouseX=mouse.x;
MouseY=mouse.y;
MouseL=mouse.l;
MouseR=mouse.r;
SocketSendString(Socket, "MOUSE "+str(MouseX)
+ " " + str(MouseY)
+ " " + str(MouseL)
+ " " + str(MouseR)
);
}
else if (SocketHasData(Socket))
{
ParsePacket(SocketGetString(Socket));
}
}
void ParsePacket(string s)
{
string a = GetToken(s, " ", 0);
if (!strcmp(a, "MOUSE"))
{
// Parse a mouse packet.
MouseX = val(GetToken(s, " ", 1));
MouseY = val(GetToken(s, " ", 2));
MouseL = val(GetToken(s, " ", 3));
MouseR = val(GetToken(s, " ", 4));
}
else
{
// Dump any unaccepted input to a log.
Log("Unknown packet:" + s);
}
}