🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

winsock=slow as hell?

Started by
8 comments, last by InfestedFurby 23 years, 6 months ago
i have very recently been learning winsock and my first network game is a client/server tron game that works perfectly except it only updates about 5 times a second.... here is the code for my main loop (off the server but the client is almost exactly the same) do{ //change dir for you if(key[KEY_UP])dir=0; if(key[KEY_LEFT])dir=3; if(key[KEY_DOWN])dir=2; if(key[KEY_RIGHT])dir=1; if(key[KEY_ENTER] && bombing==0)bombing=1; if(!key[KEY_ENTER])bombing=0; //send results load_packet(buff,dir,bombing); error = send (s[1],(char *)buff,sizeof(buff),0); //error = send (s[1],(char *)&dir,sizeof(dir),0); //error = send (s[1],(char *)&bombing,sizeof(bombing),0); if ((error==0)||(error==SOCKET_ERROR)) { cout << "Error: Player 1 quit!\n"; WSACleanup (); return 0; } //change dir for other guy error = recv (s[1],( char *)buff,sizeof(buff),0); //error = recv (s[1],( char *)&dir2,sizeof(dir2),0); //error = recv (s[1],( char *)&bombing2,sizeof(bombing2),0); if ((error==0)||(error==SOCKET_ERROR)) { cout << "Error: Player 1 quit!\n"; WSACleanup (); return 0; } unload_packet(buff,dir2,bombing2); //move you if(dir==0&&y>0)y--; if(dir==3&&x>0)x--; if(dir==2&&y0)y2--; if(dir2==3&&x2>0)x2--; if(dir2==2&&y2<SCREEN_H-1)y2++; if(dir2==1&&x2<SCREEN_W-1)x2++; putpixel(screen,x,y,70); putpixel(screen,x2,y2,40); } something like that...... anyway......... when i run the server and client on one computer, the game runs at lightening speed (as it should be) but when i tested the game out on 2 computers (28.8 and cable) it ran really slow a 28.8 should get (at an abslute minimum ) 1000 bits per second and i am sending 32 bits per game loop (2 for the send and 2 for the recv) unless i am extreamly stupid (whitch i might be...) i should be able to update the status of the game AT LEAST 1000/32=31.25 times a second and yet i am only getting 5 WHAT IS WRONG WITH ME??????? Infested Furby infestedfurby.cjb.net infestedfurby@hotmail.com
Infested Furbyinfestedfurby@hotmail.cominfestedfurby.cjb.net
Advertisement
Well, depending on what protocol you are using, the Winsock provider can buffer your send requests and send them as a larger packet.

Dire Wolf
direwolf@digitalfiends.com
[email=direwolf@digitalfiends.com]Dire Wolf[/email]
www.digitalfiends.com
5-10 updates a second is what many games utilize.

If you have to send tons of tiny packets, try bunching them together. I usually send data about 5 times a seconds and interpolate everything.

-LostLogic
webmaster@lostlogic.com

LostLogicwww.GamerOutfit.comXBox 360 Community Games Reviews and NewsExisled - 2D/3D Shooter for XBox 360

Possible causes :
-Nagel Algorithm enabled for both client and server, causes packet buffering
-using blocking sockets
-logic error in game loop

Good Luck

-ddn
It seems that the most likely problem that is slowing down my program is winsock buffering my packets and sending them all at once. Is there any way I can force winsock to bypass the buffer and send the packet immediatly???
Infested Furbyinfestedfurby@hotmail.cominfestedfurby.cjb.net
It seems that the most likely problem that is slowing down my program is winsock buffering my packets and sending them all at once. Is there any way I can force winsock to bypass the buffer and send the packet immediatly???
Infested Furbyinfestedfurby@hotmail.cominfestedfurby.cjb.net
Have you tried using streaming sockets?

Put up your winsock init code and maybe we can help you more.
sizeof(buf) looks suspicous to me. First off sizeof won''t work at all if you''re dynamically allocating buf. And if buf is statically allocated you''re probably going to send a lot more data than is actually in the buffer.

You''re not ending up sending 64k with each send are you? e.g.

char buf[65536]
FillBuf(buf)
send(socket, buf, sizeof(buf), 0); // BIG send coming up...

-Mike
Its the nagle
When you create the socket, you can pass a flag that disables it.

You''ll probably want to switch to UDP eventually as well....
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
buf is 2 bytes long (not dynamic)

what is the flag u pass to disable winsock buffering?

Infested Furbyinfestedfurby@hotmail.cominfestedfurby.cjb.net

This topic is closed to new replies.

Advertisement