Finally launched my app that uses Apple's Network framework

TLDR; Launched my game which uses Network framework – Other Words.

I watched Advances in Networking, Part 2 and used the WWDC 2019 Tic-Tac-Toe sample app as a starting point. At a past job I had worked with CocoaAsyncSocket for an app that controlled ceiling fans, so I knew some things. I'm not a network expert by any means.

I read through a bunch of threads on these forums. The Network framework documentation could be better. Definitely glad there was some WWDC sample code! Information on creating networked games in general is also hard to come by.

After reading some articles and Stackoverflow answers, I basically broke the game up into lots of micro-steps. Up to 30 steps per second. Steps are sent from server to clients and have to be acknowledged before the game can advance to the next step. This works for this style game on local Wi-Fi, but I have now read that massive multiplayer games have a different approach to account for lag.

My app uses Bonjour and TCP. The player that creates the game is the server (NWListener) and all other players are clients (NWBrowser).

I tried UDP to see if that would help get more messages per second to more clients. (I ended up taking that code out however.) I reduced the bytes of each message by changing property names to just one or two letters. (Not sure if that made much difference.) I shut down the Listener and Browser after the game started because it seemed keeping those running decreased the number of messages (game steps) I could get per second.

A couple things I did differently from the sample code is I have the client side (NWBrowser) instantiate its NWConnection and open it as soon as the browseResultsChangedHandler is called. A player identifier messages is sent when the connection is ready.

The server side (NWListener) gets its Connection instance from newConnectionHandler. When the connection receives the player identifier message from the client, it sends a game invite message.

I may write up a blog post, but if anyone has any questions about my experience creating this app I could answer them here. Thanks!







Replies

Launched my game which uses Network framework

Congrats!

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
That's excellent that you launched your game using Network Framework, congratulations!
If you see any areas where the documentation could be improved, please let us know.


Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com