Sign in to follow this  
Paladin2005

Winsock FPS Problem

Recommended Posts

Hi , Im making a simple game with network, my program is sending 4 variables at the moment , by putting them into the const chars char xbuffer [5]; // buffer for x of man char ybuffer [5]; // buffer for y of man char facing [5]; // buffer for direction of facing char rotation[5]; // rotation of man then sending them to the other person using send(). and ofcourse the other person receiving them using recv , then reconverting them to the right variables etcetc. , My problem is when my client connects, my computers fps for the game drops to as low as the other computers fps running my clients (which has alot less powerful graphics card) . emmm how do I stop this from happening , Thank you in advance, Mark

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
> My problem is when my client connects, my computers fps for the
> game drops to as low as the other computers fps running my clients
> (which has alot less powerful graphics card).

Use a fixed interval for the updates, like 10 or 30 times per second.
This way the updates will have a fixed framerate, and the rendering
framerate will be independent from the simulation framerate. If a
computer is faster then it will have a higher rendering framerate.
If slower, it will drop frames and render less frames, but supply
the simulation data with the fixed rate.

Viktor

Share this post


Link to post
Share on other sites
Do NOT start using threads unless you know you can synchronise the data, or at the least are familiar with how they work.

I would advise the use of a nonblocking socket, and only recv if the socket has pending data - use select() to find this out.

You don't really need to use the windows specific asynchronous sockets (in fact your code will be more portable if you don't) as these generate windows messages on pending data, and effectively wrap select() functionality.




Share this post


Link to post
Share on other sites
Quote:

Do NOT start using threads unless you know you can synchronise the data, or at the least are familiar with how they work.

I would advise the use of a nonblocking socket, and only recv if the socket has pending data - use select() to find this out.

You don't really need to use the windows specific asynchronous sockets (in fact your code will be more portable if you don't) as these generate windows messages on pending data, and effectively wrap select() functionality.


im having a similar problem where my recv() waits

how exactly do i use the select function to check if my socket has data

Share this post


Link to post
Share on other sites
Using select with UDP (complete (simple) send/receive echo server example)
Using select with TCP

Two methods:

1. Leave the socket set to blocking. Use select() then read the socket when data is available.
2. Set the sock to non-blocking at startup. Read the socket and call WSAGetLastError() and check for (WSA)EWOULDBLOCK (no data is available).

For UDP sockets, I benchmarked using (1) against (2) and found the (2) was faster (though either method is fine for a game application: the difference in overhead for both methods is minimal WRT total game overhead).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
use select(...){recv(...);}
its the simple way of doing it and wont take too much changing to your code

really just put if select block around your recvs
so if there is nothing recieved you wont block trying to recieve something that hasnt arrived yet

btw, multithreading may sound scarry, but for the most parts i have no problems with multithreading, but you wont gain any advantage by using it unless your running on a multi cpu or core pc
your fps would still be the same almost

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this