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

Networking

9 posts in this topic

So I am currently making a game and I want to have online multiplayer 1v1. I have never done any type of networking before and I was wondering if anyone could point me in the direction of good tutorials. I have looked and am having a hard time finding anything. I am using C++ and SFML.

1

Share this post


Link to post
Share on other sites
How much abstraction do you need? I use wsock2, winsock...
It's great for what I need, but might be too much work for your needs.
1

Share this post


Link to post
Share on other sites
 (And it's normally < 100 lines of code)

I highly doubt that since native functions provided by most operating systems dont implement any sort of packet division. Thats basically sth one has to do himself or use a library.

0

Share this post


Link to post
Share on other sites
 (And it's normally < 100 lines of code)

I highly doubt that since native functions provided by most operating systems dont implement any sort of packet division. Thats basically sth one has to do himself or use a library.

 

http://www.pcs.cnu.edu/~dgame/sockets/client.c

http://www.pcs.cnu.edu/~dgame/sockets/server.c

 

Check those out, they are the simplest forms of socket communication examples.  Packet division depending on what you mean is handled at the hardware level or at the underlying os level.  In short if you send a string you get the string on the other side.  You will need to devise a terminating character or sequence so that you can tell what part of your string represents an entire message but this isn't very difficult either.  I often use a character that I know will not appear within the actual message (say char 1).  When I receive a char 1 break the message, parse the JSON object act and respond.  It really is that simple for basic networking.

2

Share this post


Link to post
Share on other sites

SFML provides a network abstraction layer, why not consider using it?

 

Also, I suggest you check out the multiplayer forum on this site, and read over the FAQ there, it has tons of answers about writing multiplayer games, from no experience to advanced.

1

Share this post


Link to post
Share on other sites
 (And it's normally < 100 lines of code)

I highly doubt that since native functions provided by most operating systems dont implement any sort of packet division. Thats basically sth one has to do himself or use a library.

To be honest, it is about this number of lines, remember that the server and client in most examples also duplicate some code, (on the reading and sending).

 

What I suggest is to create your own socket wrapper because it will ultimately simplifiy things and then allows you to solve things in an encapsulated manner (i.e how you deal with Nagle's algorithm etc...)

 

The great thing about network programming is that it isn't too hard. (Unless I assume, you get to MMORPG levels of things ;)

1

Share this post


Link to post
Share on other sites

I've thought about this myself and I think it depends on the type of 1v1 game. If it is real-time action, I would suggest researching GGPO and how it has gained its reputation as having the best latency hiding netcode for 1v1 fighting games. http://en.wikipedia.org/wiki/GGPO

 

I can't find any clear implementation discussions but from the looks of it, it is should be possible to implement it based on the clock synchronization GDNet article here:

http://www.gamedev.net/page/resources/_/technical/multiplayer-and-network-programming/clock-synchronization-of-client-programs-r2493

 

Basically in GGPO, all keys are sent peer-to-peer with a timestamp and from that timestamp, you can figure out what the peer's current state should be like on your screen at the current time. A history of events will need to be kept for all entities and if something is off by a game-affecting amount, a state in history is chosen and the correction is predicted and applied.

 

For something like this, you'd basically have to dabble at the socket level.

0

Share this post


Link to post
Share on other sites
 (And it's normally < 100 lines of code)

I highly doubt that since native functions provided by most operating systems dont implement any sort of packet division. Thats basically sth one has to do himself or use a library.

To be honest, it is about this number of lines, remember that the server and client in most examples also duplicate some code, (on the reading and sending).

 

What I suggest is to create your own socket wrapper because it will ultimately simplifiy things and then allows you to solve things in an encapsulated manner (i.e how you deal with Nagle's algorithm etc...)

 

The great thing about network programming is that it isn't too hard. (Unless I assume, you get to MMORPG levels of things ;)

 

I agree, make a simple wrapper class, attach the class to the characters or to the game manager if your using one and voila.  Yes you will need some form of a server but the networking itself is all the same.  Create a socket, connect or accept it, send and receive and that's all she wrote.  Writing advanced servers for say MMO's or large networking social systems or what have you is just a matter of writing the logic based on multiple "socket" connections.  Where each socket somehow relates to a "user" or "player".

0

Share this post


Link to post
Share on other sites



(And it's normally < 100 lines of code)

I highly doubt that since native functions provided by most operating systems dont implement any sort of packet division. Thats basically sth one has to do himself or use a library.
http://www.pcs.cnu.edu/~dgame/sockets/client.c
http://www.pcs.cnu.edu/~dgame/sockets/server.c

Check those out, they are the simplest forms of socket communication examples. Packet division depending on what you mean is handled at the hardware level or at the underlying os level. In short if you send a string you get the string on the other side. You will need to devise a terminating character or sequence so that you can tell what part of your string represents an entire message but this isn't very difficult either. I often use a character that I know will not appear within the actual message (say char 1). When I receive a char 1 break the message, parse the JSON object act and respond. It really is that simple for basic networking.
What I meant with packet division is message-splitting (if thats better to understand).
Im going to try to explain what I really meant further below.
.
Btw the code you provided contains send and recv functions that arent implemented appropriately.
There are 2 problems.
Lets say you wish to send 10 bytes for simplicity's sake.
#1.
x = send(socket, data[0], 10,...)
x <= 0 (either -1 or 0 -> nothing sent; trivial)
x = 10 (everything sent; trivial)
0<x<10 (not everything was sent due to the operating system's internal buffer storing outgoing data being full -->
this implies that one has to track how many bytes were really sent and which need to resend)
#2
lets say send(socket, data[0], 10, ..) returned 10 - so you sent the everything over tcp
x = recv(socket, data[0], 10, ..)
x does not have to be 10!
cases that can happen: x<=0, x=10 or 0<x<10
if 0<x<10 happens, you cant simply assume the data received can be used from now on - because its not a whole "message"/"packet" - its not complete...

"If you send a string you get a string on the other side" This is partially true - you get your string but not in the same shape (damn its really hard to explain =/)
"HelloWorld" 10 bytes: send() may only send lets say 3 bytes -> only "Hel" will be sent
so you need to send the rest by repeating the process
Same happens on the receiving side - you dont have to get 10 bytes or 3.. It can be in different sizes. But its true, you will have your 10 bytes in the end.

Anyway, because of that its essential to implement Streaming-Classes that can store and track how much data has been succeessfully sent & received. Edited by Aphton
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