<?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"><channel><title><![CDATA[Cant get Unity client to connect to server]]></title><description><![CDATA[<p>Hi, I am trying to build a chat system with unity3d but I can't seem to get client to join the room.</p>
<p>What am I doing wrong?</p>
<p>Here is my code:<br />
`</p>
<pre><code>  using UnityEngine;
  using System.Collections;
  using System.Collections.Generic;
  using System;
  using Colyseus;
  using UnityEngine.UI;

  using GameDevWare.Serialization;
  using GameDevWare.Serialization.MessagePack;

  public class ColyseusClient : MonoBehaviour {

    Client client;
    Room room;

    public InputField input;
    public Button button;

    public string serverName = &quot;localhost&quot;;
    public string port = &quot;8080&quot;;
    public string roomName = &quot;chat&quot;;

    // map of players
    Dictionary&lt;string, GameObject&gt; players = new Dictionary&lt;string, GameObject&gt;();

    // Use this for initialization
    IEnumerator Start () {
      String uri = &quot;ws://&quot; + serverName + &quot;:&quot; + port;
      Debug.Log (uri);
      client = new Client(uri);
      client.OnOpen += OnOpenHandler;
      client.OnClose += OnCloseHandler;

      Debug.Log (&quot;Let's connect the client!&quot;);
      yield return StartCoroutine(client.Connect());

      Debug.Log (&quot;Let's join the room!&quot;);

      room = client.Join(roomName, new Dictionary&lt;string, object&gt;() {
        { &quot;create&quot;, true }
      });

      room.OnReadyToConnect += (sender, e) =&gt; {
        Debug.Log(&quot;Ready to connect to room!&quot;);
        StartCoroutine (room.Connect ());
      };

      room.OnJoin += OnRoomJoinHandler;
      room.OnMessage += OnMessageHandler;

    }

    void OnOpenHandler (object sender, EventArgs e) {
      Debug.Log(&quot;Connected to server. Client id: &quot; + client.id);
    }

    void OnCloseHandler (object sender, EventArgs e) {
      Debug.Log (&quot;Connection closed&quot;);
    }

    void OnRoomJoinHandler (object sender, EventArgs e) {
      Debug.Log(&quot;Joined room successfully.&quot;);
    }

    void OnMessageHandler (object sender, MessageEventArgs e) {
      var message = (IndexedDictionary&lt;string, object&gt;) e.message;
      Debug.Log(e.message);
    }


    void OnApplicationQuit() {
      // Make sure client will disconnect from the server
      room.Leave ();
      client.Close ();
    }
  }
</code></pre>
<p>`</p>
]]></description><link>http://discuss.colyseus.io/topic/120/cant-get-unity-client-to-connect-to-server</link><generator>RSS for Node</generator><lastBuildDate>Wed, 19 Aug 2026 23:45:54 GMT</lastBuildDate><atom:link href="http://discuss.colyseus.io/topic/120.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 25 Jul 2018 14:38:33 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Cant get Unity client to connect to server on Wed, 25 Jul 2018 14:43:58 GMT]]></title><description><![CDATA[<p>Hi, I am trying to build a chat system with unity3d but I can't seem to get client to join the room.</p>
<p>What am I doing wrong?</p>
<p>Here is my code:<br />
`</p>
<pre><code>  using UnityEngine;
  using System.Collections;
  using System.Collections.Generic;
  using System;
  using Colyseus;
  using UnityEngine.UI;

  using GameDevWare.Serialization;
  using GameDevWare.Serialization.MessagePack;

  public class ColyseusClient : MonoBehaviour {

    Client client;
    Room room;

    public InputField input;
    public Button button;

    public string serverName = &quot;localhost&quot;;
    public string port = &quot;8080&quot;;
    public string roomName = &quot;chat&quot;;

    // map of players
    Dictionary&lt;string, GameObject&gt; players = new Dictionary&lt;string, GameObject&gt;();

    // Use this for initialization
    IEnumerator Start () {
      String uri = &quot;ws://&quot; + serverName + &quot;:&quot; + port;
      Debug.Log (uri);
      client = new Client(uri);
      client.OnOpen += OnOpenHandler;
      client.OnClose += OnCloseHandler;

      Debug.Log (&quot;Let's connect the client!&quot;);
      yield return StartCoroutine(client.Connect());

      Debug.Log (&quot;Let's join the room!&quot;);

      room = client.Join(roomName, new Dictionary&lt;string, object&gt;() {
        { &quot;create&quot;, true }
      });

      room.OnReadyToConnect += (sender, e) =&gt; {
        Debug.Log(&quot;Ready to connect to room!&quot;);
        StartCoroutine (room.Connect ());
      };

      room.OnJoin += OnRoomJoinHandler;
      room.OnMessage += OnMessageHandler;

    }

    void OnOpenHandler (object sender, EventArgs e) {
      Debug.Log(&quot;Connected to server. Client id: &quot; + client.id);
    }

    void OnCloseHandler (object sender, EventArgs e) {
      Debug.Log (&quot;Connection closed&quot;);
    }

    void OnRoomJoinHandler (object sender, EventArgs e) {
      Debug.Log(&quot;Joined room successfully.&quot;);
    }

    void OnMessageHandler (object sender, MessageEventArgs e) {
      var message = (IndexedDictionary&lt;string, object&gt;) e.message;
      Debug.Log(e.message);
    }


    void OnApplicationQuit() {
      // Make sure client will disconnect from the server
      room.Leave ();
      client.Close ();
    }
  }
</code></pre>
<p>`</p>
]]></description><link>http://discuss.colyseus.io/post/412</link><guid isPermaLink="true">http://discuss.colyseus.io/post/412</guid><dc:creator><![CDATA[charlesonunze]]></dc:creator><pubDate>Wed, 25 Jul 2018 14:43:58 GMT</pubDate></item><item><title><![CDATA[Reply to Cant get Unity client to connect to server on Invalid Date]]></title><description><![CDATA[<p>What does the console print? And did you assign the script to a Gameobject?</p>
]]></description><link>http://discuss.colyseus.io/post/442</link><guid isPermaLink="true">http://discuss.colyseus.io/post/442</guid><dc:creator><![CDATA[cemck]]></dc:creator><pubDate>Invalid Date</pubDate></item></channel></rss>