Closed Shivang44 closed 5 years ago
Hi, thanks for raising the issue, would be happy to help you out.
Can you please share more of the code, for example the Socket initialization code? Which server are you trying to connect to? Localhost, remote server, integration test server?
Also, there should be some logging happening on both the client and backend to help you with the debug process.
Hi, thanks for raising the issue, would be happy to help you out.
Can you please share more of the code, for example the Socket initialization code? Which server are you trying to connect to? Localhost, remote server, integration test server?
Also, there should be some logging happening on both the client and backend to help you with the debug process.
Thanks for the quick response! At work, will get this to you after work.
Here is the script I'm testing your library with in Unity:
using System;
using System.Collections.Generic;
using Phoenix;
using UnityEngine;
public class GameServerNew : MonoBehaviour
{
void Start() {
var socketFactory = new WebsocketSharpFactory();
var socket = new Socket(socketFactory);
socket.OnOpen += onOpenCallback;
socket.OnMessage += onMessageCallback;
var user = _userData();
var channelParams = new Dictionary<string, string>();
channelParams.Add("access_token", user.access_token);
channelParams.Add("user_id", $"{user.id}");
channelParams.Add("character_id", $"{user.id}");
socket.Connect(Config.WEBSOCKET_URL, channelParams);
var roomChannel = socket.MakeChannel("room:0,0");
roomChannel.On(Message.InBoundEvent.phx_close, m => Debug.Log(m));
roomChannel.Join(null)
.Receive(Reply.Status.Ok, r => Debug.Log(r))
.Receive(Reply.Status.Error, r => Debug.Log(r));
}
private void onMessageCallback(string message)
{
throw new NotImplementedException();
}
private void onOpenCallback()
{
throw new NotImplementedException();
}
private User _userData() {
return JsonUtility.FromJson<User>(PlayerPrefs.GetString("user_data"));
}
}
Nothing ever gets outputted to the Unity console. On the server I get a connection and my connect() function gets called in my Phoenix.Socket, but the join function never gets called.
Which server are you trying to connect to? Localhost, remote server, integration test server?
Localhost
Also, there should be some logging happening on both the client and backend to help you with the debug process.
There is nothing logged on the Unity3D client. On the server I get
[info] CONNECTED TO ServerWeb.UserSocket in 2ms
Transport: :websocket
Serializer: Phoenix.Socket.V1.JSONSerializer
Connect Info: %{}
Parameters: %{"access_token" => "22c8b919941d6dff6d49fa4f5c4c43586ed556d8d7ca8be488e4049f97e431d8", "character_id" => "1", "user_id" => "1"}
But I don't actually make it to the join
function when I try to join a channel from the client.
So, I just updated the Heroku integration tests server for this project to latest Phoenix and Elixir versions to make sure it's still working, and all tests are still passing. I think we need to perform some debug steps on your end to find the cause.
One possibility is an exception being thrown in the callback are causing problems. Can you please make sure the Unity console isn't showing any errors?
I think we can exclude misconfiguration on the server side, because you mention there are no logs at all with regards to channel join events. We need to make sure the client side is actually performing the channel join flow. We need as many logs as we can.
Try this to enable the debugger:
public sealed class BasicLogger : ILogger {
#region ILogger implementation
public void Log(Phoenix.LogLevel level, string source, string message) {
Console.WriteLine("[{0}]: {1} - {2}", level, source, message);
}
#endregion
}
var socket = new Socket(socketFactory, new Socket.Options
{
logger = new BasicLogger()
});
Thanks for the help in debugging this. Looks like there is an error with the websocket-sharp library:
But it's curious as to why opening the socket itself works, but joining a channel doesn't.
Did I perhaps misread the docs? Is this default built in delayed executor timer good enough for unity3d? Or do I need to implement my own for this to work?
One possibility is an exception being thrown in the callback are causing problems. Can you please make sure the Unity console isn't showing any errors?
THAT WAS THE ISSUE. Thank you so much and sorry for wasting your time. Do you know why this this wasn't actually raising an exception in the unity3d debugger? It makes no sense, the console was just empty. But removing the throw new NotImplementedException();
allows me to join a channel.
Is something swallowing this exception somewhere? Looks like websocketsharp catches it and sends some error somewhere?
I think it's part of the WebSocketSharp implementation. Many network/websocket implementations in C# swallow callback exceptions, since they shouldn't crash the network code, I've seen it with BestHTTP.
Glad it was resolved! Thanks for using this library 🚀
I copied the implementation using websocket-sharp from the integration test folder.
I'm able to connect to the websocket server with
socket.Connect
, but when try to join a channel withnothing happens. It doesn't raise an error on the server or client side.
Does anybody know what could be happening? I'm using JSON.net.