Navigation

    Colyseus
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Users
    1. Home
    2. charlesonunze
    charlesonunze

    charlesonunze

    @charlesonunze

    Chat Follow Unfollow
    0
    Reputation
    1
    Posts
    527
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    • Profile
    • More
      • Continue chat with charlesonunze
      • Flag Profile
      • Following
      • Followers
      • Topics
      • Posts
      • Best
      • Groups
    charlesonunze Follow

    Posts made by charlesonunze

    Cant get Unity client to connect to server

    Hi, I am trying to build a chat system with unity3d but I can't seem to get client to join the room.

    What am I doing wrong?

    Here is my 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 = "localhost";
        public string port = "8080";
        public string roomName = "chat";
    
        // map of players
        Dictionary<string, GameObject> players = new Dictionary<string, GameObject>();
    
        // Use this for initialization
        IEnumerator Start () {
          String uri = "ws://" + serverName + ":" + port;
          Debug.Log (uri);
          client = new Client(uri);
          client.OnOpen += OnOpenHandler;
          client.OnClose += OnCloseHandler;
    
          Debug.Log ("Let's connect the client!");
          yield return StartCoroutine(client.Connect());
    
          Debug.Log ("Let's join the room!");
    
          room = client.Join(roomName, new Dictionary<string, object>() {
            { "create", true }
          });
    
          room.OnReadyToConnect += (sender, e) => {
            Debug.Log("Ready to connect to room!");
            StartCoroutine (room.Connect ());
          };
    
          room.OnJoin += OnRoomJoinHandler;
          room.OnMessage += OnMessageHandler;
    
        }
    
        void OnOpenHandler (object sender, EventArgs e) {
          Debug.Log("Connected to server. Client id: " + client.id);
        }
    
        void OnCloseHandler (object sender, EventArgs e) {
          Debug.Log ("Connection closed");
        }
    
        void OnRoomJoinHandler (object sender, EventArgs e) {
          Debug.Log("Joined room successfully.");
        }
    
        void OnMessageHandler (object sender, MessageEventArgs e) {
          var message = (IndexedDictionary<string, object>) e.message;
          Debug.Log(e.message);
        }
    
    
        void OnApplicationQuit() {
          // Make sure client will disconnect from the server
          room.Leave ();
          client.Close ();
        }
      }
    

    `

    posted in Questions & Help •