WinSock - How do I fix delay.

closed account (2NywAqkS)
I've made a working multi-client server(and client) but the method I use to update all the clients isn't very good.
1
2
3
4
5
6
7
8
9
10
11
12
13
void UpdateClient()
{
	for (unsigned int i = 0; i < playerVector.size(); i++)
	{
		for (unsigned int j = 0; j < playerVector.size(); j++)
		{
			std::stringstream stream;
			stream << j << "," << playerVector.size() << "," << playerVector[j].x << "," << playerVector[j].y;
			send(playerVector[i].socket, stream.str().c_str(), stream.str().length(), 0);
			Sleep(100);
		}
	}
}


If it isn't obvious, it sends the information of each player to every player with an identification number at the start. If I don't have that Sleep function and the end. only one player tends to update, however it does give a noticeable lag.

I realise this is probably the wrong way of doing this. What should I do? If it helps I can upload more code. Feel free to ask questions.

Thanks,
Rowan.

Last edited on
closed account (2NywAqkS)
Ah, solved. The trick is to put it all into one stream. I separated it out with |s and that really did the trick.
Topic archived. No new replies allowed.