• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Xanather

Overflowing Buffers!

9 posts in this topic

Context (if it matters): Creating a game networking system using C# and .net's TcpClient/NetworkStream (no network library).

The client and server programs both have two buffers, the upload buffer and the download buffer, both are 64kb in size (I am talking about application buffers here).

The download buffer is used for downloading available bytes on the network stream at the start of every game tick.
The upload buffer is used for sending all messages (within that game tick) at the end of every game tick.

Current problems I am experiencing is how to handle this all:[list]
[*]Currently the download buffer can easily overflow, if available bytes available on the stream are greater than the byte buffer (64kb) minus the current data stored in the byte buffer (due to possibly previous half messages received in previous ticks) then the buffer obviously overflows.
[*]Another problem I have is the upload buffer, throughout a game tick messages are added to the upload buffer; which is then sent at the end of the game tick. If massive messages are sent within one game tick (greater than 64kb) then the upload buffer overflows.
[/list]
[b]Question(s): How can I handle the two dot points above? is overflowing buffers normal? (I remember playing gmod a few times and got the buffer overflow errors). Do I even need a upload buffer? should I just write directly to the stream once a message has been created during a tick?[/b]

Right now whenever I try sending even one chunk (containing tile data) from the server -> client the upload buffer overflows on the server and the download buffer would overflow on the client. I solved the problem by forcefully making the server send the upload buffer multiple times before the end of a game tick and making the client download the chunk over more than 1 tick (by checking if the buffer is close to overflowing when reading 256 byte increments from the stream during a tick). But I feel like I hackishly solved the problem and my code is no longer consistent.

All replies are appreciated, thanks.

Edit: I would read available bytes from the stream instantaneously as they arrive/are sent but each client is not assigned a thread. Also: sorry if I am asking too much :( Edited by Xanather
0

Share this post


Link to post
Share on other sites
@Ripiz. Ok, I will try change the size to 1MB (which will allow for bits of world chunks). There is no other performance decrease in doing this except for more RAM usage right? Edited by Xanather
0

Share this post


Link to post
Share on other sites
Using a larger buffer uses more RAM, and, at the extreme, may cause heap fragmentation (you're a while away from that danger yet I think.)

The other problem with big buffers is that nothing else can be sent at the same time on that same stream. If you're using a single TCP connection for all game data, that means all chat, world movement, friend requests, and other such information is blocked by transferring the large amount of data. You might be better off defining a protocol that first establishes a chunk ("define chunk 123 to have size 800 kB") and then sends pieces of that chunk as packets ("here's the data for offset 324,000 size 2,000 for chunk 123") and finally, when all pieces are sent, sends the "use chunk" message.
2

Share this post


Link to post
Share on other sites
That makes sense, your saying to use a complete different TCP stream (different port) or use UDP for tile chucks? Or during when the connection is being established between the server/client (handshakes etc..)? Edited by Xanather
0

Share this post


Link to post
Share on other sites
You can use another TCP stream -- you can even use HTTP for larger downloads; HTTP is a fine bulk data transfer protocol with lots of good infrastructure available.

What I was actually suggesting was that you time-slice the existing TCP stream, though. If you already have "packet types" over TCP (which I presume you do, else you're going to want to add that,) then you can define a number of smaller packets, which, when put together, transfer the entire large chunk of data. The benefit is that you can send different kinds of packets in between each fragment of the big file, so the entire connection doesn't appear to "freeze" while downloading one big thing.
1

Share this post


Link to post
Share on other sites
Yes I do have prefixed messages types (byte) and message lengths (short).
Well, that makes sense, so just send parts of the chunk each tick? (and each tick chunk could have just one x row of the whole chunk?).

Also is there any point to having a application upload buffer? Should I write directly to the stream every time something happens (even if its just a chat message being sent)? I feel having the program upload everything in one tick is better to do than write several times (if not 20+ times) per tick.

thanks for your help hplus.
0

Share this post


Link to post
Share on other sites
Yes, it's usually better to buffer all outgoing messages and send them in one fell swoop when the "tick time" comes. If you ever change to UDP, that's a requirement. For TCP, the OS will do some of that buffering for you, if you do not turn off Nagling (i e, do not turn on TCP_NODELAY.)
1

Share this post


Link to post
Share on other sites
Ahhh, right, I have turned that off xD (in order to lower latency), so I'm going to stick to what I have.

thanks again [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] Edited by Xanather
0

Share this post


Link to post
Share on other sites
Done! Implemented it successfully (over several ticks) and it works like a charm with only 256kb application buffers :D.
0

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  
Followers 0