<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Vlad on Medium]]></title>
        <description><![CDATA[Stories by Vlad on Medium]]></description>
        <link>https://medium.com/@wladd?source=rss-1312364e45b1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Sdnyl8JMjqUBEzo-.jpg</url>
            <title>Stories by Vlad on Medium</title>
            <link>https://medium.com/@wladd?source=rss-1312364e45b1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 15:44:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@wladd/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Multiplayer chat room for iOS game]]></title>
            <link>https://medium.com/@wladd/multiplayer-chat-room-for-ios-game-430a18c40a2e?source=rss-1312364e45b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/430a18c40a2e</guid>
            <dc:creator><![CDATA[Vlad]]></dc:creator>
            <pubDate>Thu, 08 Mar 2018 14:05:19 GMT</pubDate>
            <atom:updated>2018-03-09T11:02:17.978Z</atom:updated>
            <content:encoded><![CDATA[<p>This article describes an attempt to add multiplayer component to my iOS game <a href="https://itunes.apple.com/us/app/cityzen-geography-game/id1243070321">Cityzen — geography game</a>. As first-time indie game developer, I’ve fallen into a trap of underestimating time and effort needed to support it, and multiplayer was eventually removed from first version of the game.</p><p>Cityzen — geography game supports player leaderboards via Apple’s <a href="https://developer.apple.com/game-center/">Game Center.</a> In each game turn, player is presented with a city name and should find it’s location on the globe. Score for each turn is determined via simple formula that takes into account distance between player’s location and actual location (latitude/longitude coordinates). What should have made the game more fun was to make player aware of all others playing in the same turn, see their attempts and award highest score to player closest to the target.</p><p>One valid and actually more sensible option was to go with something like <a href="https://firebase.google.com/">Firebase</a> and to have all I could possibly need at my fingertips, with more than generous limits needed for hobby project like Cityzen was — but where’s the fun in that?</p><p>So, what I did ultimately led to dropping this from the game due to unnecessary additional complexity, but was a fun learning experience. In short, this shows how easy it is to make iOS game talk to Go based server via websockets. We’ll just glance over most basic functionality and leave any complexities for blog post #2.</p><p>We’ll go ahead and create new SceneKit Game project in XCode. We’ll also need <a href="https://github.com/daltoniam/Starscream">Starscream</a> library, so let’s add it via Cocoa pods. Result should look similar to this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pUxWCq67O7h4xeqVhYJFpA.png" /></figure><p>From GameViewController.swift we’ll remove all placeholder content and inherit from WebSocketDelegate, so it looks like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iuj_7fGI1LsZFodF1GSSMg.png" /></figure><p>We’ll add some plumbing needed for websockets, and instead of coding user interface we will just add timed call to sendMessage() function, so same message is sent each 10 seconds to server. It should look something like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SgLEChUNlM83VUPvoA77kQ.png" /></figure><p>Moving on to server now, Go has excellent support for websockets via Gorilla’s <a href="https://github.com/gorilla/websocket">websocket</a> package. In the interest of keeping it simple, let just clone the repository</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AfFe2i01KC4YgQ8tAXtk7w.png" /></figure><p>and run chat example</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rka-U6OtXyvFEeyiGHjuhA.png" /></figure><p>Example comes with sample http page, so we’ll open <a href="http://localhost:8080/">localhost:8080</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sbc7bLOlPxBEfI4GGv6P8Q.png" /></figure><p>Now if we run our XCode project we’ll see messages being sent and received on both ends (both from browser and our iOS project):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*42MNmo1508kINRG-_p9x3w.png" /></figure><p>For quick and dirty proof-of-concept, this was more than enough to make me happy. It’s worth noting that Go code is clean and short and I feel it’s not a huge effort to extend it with persistence, dynamic scoring based on each player’s location, etc. — than again, I was wrong before ;)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=430a18c40a2e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>