Advertisement

Winsock FPS Problem

Started by November 05, 2005 10:20 AM
7 comments, last by GameDev.net 19 years, 3 months ago
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
ahh but it seems my recv function waits until it gets a value , before anything happens : / , I think
Advertisement
Quote:
Original post by Paladin2005
ahh but it seems my recv function waits until it gets a value , before anything happens : / , I think


put recv in a separate thread.
------------------------------BASIC programmers don't die, they just GOSUB and don't return.
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.




Winterdyne Solutions Ltd is recruiting - this thread for details!
ahh Thank You Winterdye :) ,

+ reps !
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
Advertisement
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).

This topic is closed to new replies.

Advertisement