• 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
lonewolff

TCP Packet boundaries

5 posts in this topic

Not so much a problem but more of an coding execution standpoint.

 

I am in the middle of programming a game server using C++ & Winsock. All good so far. 8)

 

I am making a network class & I have the app at the stage now where the client will accept and disconnect multiple clients gracefully and bug free (as far as I can tell).

 

I am now stuck on how I shoud handle the recieve code.

 

The incoming data will be of a variable size with the first byte (or two) being the identifier of the incoming packet type.

 

[Byte1 (Idenifier][Byte2... ByteN (Data)]    // Data length will be constant depending on what the identifier is.

 

The problem is where I should handle the recieved data. If I was going to have the class reconstuct the incoming data and check for packet boundaries, the class would have to know about all of the data types, which would then decrease re-usablility (as the class would then be 'custom written' for the application.

 

However, if I get the class to just fill a 'client buffer' for each incoming socket connection, I could get the application to reconstruct the data (and not the class). But, then this semi-defeats the purpose of having the network class.

 

Any ideas on how I can get the class to handle the incoming data better?

 

Thanks in advance.

 

 

 

 

 

0

Share this post


Link to post
Share on other sites

You could have the network class provide a safe and controlled way for each class to read from the network socket, according to a well-defined protocol. That way only the packet identifier is read, and the network class then delegates the work of parsing the remaining data to whatever class should be parsing it, elegantly. And you can still stream from the socket, instead of having to grab the entire packet at once. In this sense, the network class provides a level of abstraction, which is what you wanted.

 

If you are concerned about reusability, you should cleanly separate parsing (reading data from the packet) and actual work done. Ideally you should be able to simply strip out the parsing code and still have a working class. I don't think creating a dedicated network/class interface for each class is really going to make things better, it's probably overkill (do you really want to deal with EnemyParser, TerrainPacket, and so on?!)

1

Share this post


Link to post
Share on other sites

Thanks for your tips guys 8)

 

@hplus0603 - I didn't even think of sending the size first. That would probably solve my issue.

 

I could do something like this;

 

[Byte 1-2 (Size)][Byte 3-4 (Identifier)][Byte 5-n (Payload)]

 

This way the network class can reconstruct the data and pass it on to the main app (without the network class having to know what the data stream is).

 

The way I am planning this game to go, network traffic will be minimal (possibly once per second at peak). So, 'trigger speeds' will not be an issue.

0

Share this post


Link to post
Share on other sites

Unless your going to have more than 255 messages I think the message identifier/type only needs to be one byte. The size could be a 16-bit integer.

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