Closed jonathanleang closed 7 years ago
@jonathanleang First you need a phoenix server running, with some available channels. Once that's up and running, then you can start writing client code to connect to the server.
@Mazyod yeh i already have that setup and working with the js client I am just not sure how to read Reply and Message, they are still null
its working now, thanks
def connect(_params, socket) do {:ok, assign(socket, :user, :guest)} end
roomChannel.Join() .Receive(Reply.Status.Ok, r => okReply(r))
public void okReply(Reply r){ Debug.Log ("okReply" + r); }
Cool, you can also simply pass in the function:
roomChannel.Join()
.Receive(Reply.Status.Ok, okReply);
Thanks for the tips
@Mazyod Thanks and I got it working in unity editor, sending and reading messages, but when it's on iOS i got the following error.
2017-06-16 22:28:57.151455+0800 ProductName[6120:1690677] Warning: Libinfo call to mDNSResponder on main thread
[Debug]: socket - on open
06/16/2017 22:28:58|Fatal|Socket.Connect|System.MissingMethodException: Method not found: 'Default constructor not found...ctor() of System.ComponentModel.TypeConverter'.
at System.Activator.CreateInstance (System.Type type, System.Object[] args) [0x00000] in 2 parameters) [0x00000] in <filename unknown>:0 at ServerConnect+<ReConnect>c__Iterator0.MoveNext () [0x00000] in <filename unknown>:0 at UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) [0x00000] in <filename unknown>:0 [Info]: socket - An exception has occurred while opening. [Info]: channel - room:lobby: socket error onErrorCallback An exception has occurred while opening. ServerConnect:onErrorCallback(String) Phoenix.Socket:WebsocketOnError(IWebsocket, String) WebSocketSharp.WebSocket:acceptException(Exception, String) Phoenix.Socket:Connect(String, Dictionary
2)
socket.Connect(string.Format("{0}://{1}/socket", wsprotocol, host), new Dictionary<string, string> { { "token", token } }); lobbyChannel = socket.MakeChannel("room:lobby");
@jonathanleang I would suggest you try the Json.NET
library from the asset store. The libraries I've added in this repo (WebsocketSharp and NewtonSoft) are unfortunately not fully compatible with iOS.
Feel free to try and search for free alternatives, but from my experience, Json.NET was worth every penny.
Further reading: https://github.com/Mazyod/PhoenixSharp#unity
@Mazyod Thanks a lot, your response is so quick !
Happy to help! Thanks for giving this a try, and please let me know of any issues
@Mazyod Yep, its working on ios now with Json.NET, thank you.
@Mazyod any idea why 'Phoenix.Push' is missing ? This happend after i changed to BestHTTP Pro
TypeLoadException: Could not load type 'Phoenix.Push' from assembly 'Phoenix, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. System.Reflection.MonoMethodInfo.GetMethodInfo (IntPtr handle) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:59) System.Reflection.MonoMethodInfo.GetAttributes (IntPtr handle) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:75) System.Reflection.MonoMethod.get_Attributes () (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:245) System.Reflection.MethodBase.get_IsSpecialName () (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:184) UnityEditor.Build.BuildPipelineInterfaces.InitializeBuildCallbacks (Boolean findBuildProcessors, Boolean findSceneProcessors) (at /Users/builduser/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildPipelineInterfaces.cs:149)
@jonathanleang how are you adding PhoenixSharp code to your Unity project? Are you building it as a DLL, then linking that?
Personally, I have faced a lot of issues compiling DLLs separately in the past with Unity, and simply drop the sources directly into the Unity project.
@Mazyod thanks, fixed it by removing DLL, I only used unity to build not sure how debug DLL got there. Thanks alot, everything looks good now 👍
I am new to callbacks in unity, not sure how to read the message and replies. I did the following and got NULL as expected.