Re: Error: Failed to auto-create room [Unity Client]
// Use this for initialization
IEnumerator Start () {
String uri = "ws://" + serverName + ":" + port;
Debug.Log (uri);
client = new Client(uri);
client.OnOpen += OnOpenHandler;
client.OnClose += (object sender, EventArgs e) => isConnected = false;
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 += OnRoomJoined;
room.OnStateChange += OnStateChangeHandler;
room.Listen ("players/:id", this.OnPlayerChange);
room.Listen ("players/:id/:axis", this.OnPlayerMove);
room.Listen ("messages/:number", this.OnMessageAdded);
// room.Listen("messsages", "add", this.OnAddMessages);
// room.Listen("messsages", "replace", this.OnAddMessages);
room.Listen (this.OnChangeFallback);
room.OnMessage += OnMessage;
//
int i = 0;
while (true)
{
client.Recv();
i++;
if (i % 50 == 0) {
room.Send("111");
}
yield return 0;
}
}
void OnMessage (object sender, MessageEventArgs e)
{
var message = (IndexedDictionary<string, object>) e.message;
Debug.Log(e.message);
}
InvalidCastException: Cannot cast from source type to destination type.
ColyseusClient.OnMessage (System.Object sender, Colyseus.MessageEventArgs e) (at Assets/PluginsColesus/ColyseusClient.cs:98)
Colyseus.Room.ParseMessage (System.Byte[] recv) (at Assets/PluginsColesus/Colyseus/Room.cs:195)
Colyseus.Room.Recv () (at Assets/PluginsColesus/Colyseus/Room.cs:83)
Colyseus.Client.Recv () (at Assets/PluginsColesus/Colyseus/Client.cs:89)
ColyseusClient+<Start>c__Iterator0.MoveNext () (at Assets/PluginsColesus/ColyseusClient.cs:58)
UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)