Unity + Firebase-Database [错误] WebSocket:ws_0 - 无法连接

时间:2018-06-01 22:50:52

标签: c# firebase unity3d firebase-realtime-database

我似乎无法找到解决此错误的有效方法,更完整:

  

018-06-01 10:33:09 PM [错误] WebSocket:ws_0 - 无法连接   System.Net.Sockets.SocketException(0x80004005):无主机路由

     

2018-06-01 10:33:09 PM [错误] WebSocket:ws_0 - 握手期间的WebSocketException   Firebase.Database.Internal.TubeSock.WebSocketException:未知主机:########。firebaseio.com ---> System.Net.Sockets.SocketException:没有到主机的路由

注意,上述错误每秒重复几次,ws_#每次递增一次

Unity 2018.1.1f1

Firebase-Database:几天前的最新内容

代码:

void Start() {
    FirebaseApp.LogLevel = LogLevel.Verbose;
    FirebaseDatabase.DefaultInstance.LogLevel = LogLevel.Verbose; // Or your database instance, if not using the default.

    FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => {
        var dependencyStatus = task.Result;
        if (dependencyStatus == Firebase.DependencyStatus.Available) {
            FirebaseApp app = FirebaseApp.DefaultInstance;
            // NOTE: You'll need to replace this url with your Firebase App's database
            // path in order for the database connection to work correctly in editor.
            app.SetEditorDatabaseUrl("https://########.firebaseio.com/");
            if (app.Options.DatabaseUrl != null) app.SetEditorDatabaseUrl(app.Options.DatabaseUrl);
        } else {
            Debug.LogError(System.String.Format(
                "Could not resolve all Firebase dependencies: {0}", dependencyStatus));
            // Firebase Unity SDK is not safe to use here.
        }
    });
}

以下是我尝试访问firebase数据库

DatabaseReference mDatabaseRef = FirebaseDatabase.DefaultInstance.RootReference;
staticLocalData.thisUser = new UserData();
staticLocalData.thisUser.userID = newUser.UserId;
staticLocalData.thisUser.email = email;
staticLocalData.thisUser.firstName = firstName;
staticLocalData.thisUser.lastName = lastName;
registerData temp = new registerData();
temp.firstName = firstName;
temp.lastName = lastName;
temp.email = email;
temp.userName = userName;

Debug.Log(JsonUtility.ToJson(temp));
mDatabaseRef.Child("users").SetValueAsync("saddsa:23");  
//mDatabaseRef.Child("users").Child(newUser.UserId).SetRawJsonValueAsync(JsonUtility.ToJson(temp));

规则集:(应该允许所有)

{
  "rules": {
    ".read": true,
    ".write": true
  }
}

附加说明:

2 个答案:

答案 0 :(得分:6)

使用:

OSX Sierra 10.12.6上的Unity Editor 2018.2.5f1

脚本运行时4.x

脚本后端IL2CPP

API级别4.x

Firebase插件版本5.2.1

此问题完全相同。这似乎与Mono Websocket的实现有关,如以下问题所述:

https://github.com/firebase/quickstart-unity/issues/106

https://github.com/firebase/quickstart-unity/issues/162

Firebase开发团队通过为每个平台提供自己的本机websocket实现来解决那里描述的问题。显然,Unity Editor的实现滞后了。

解决此问题的方法是,在编辑器平台的../Firebase/Plugins/Mono/下禁用FirebaseDatabase.dll,然后直接在../Firebase/Plugins/下启用一个FirebaseDatabase.dll。 。

到目前为止,很好。

答案 1 :(得分:0)

该问题已在7月新发行的firebase_sdk_v6.2.1中修复