Unity + Firebase-Database [错误] WebSocket:ws_0-无法连接 [英] Unity+Firebase-Database[Error] WebSocket: ws_0 - could not connect

查看:142
本文介绍了Unity + Firebase-Database [错误] WebSocket:ws_0-无法连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I cant seem to figure out a working solution to this error, more complete:

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

018-06-01 10:33:09 PM [Error] WebSocket: ws_0 - could not connect System.Net.Sockets.SocketException (0x80004005): No route to host

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

2018-06-01 10:33:09 PM [Error] WebSocket: ws_0 - WebSocketException during handshake Firebase.Database.Internal.TubeSock.WebSocketException: unknown host: ########.firebaseio.com ---> System.Net.Sockets.SocketException: No route to host

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

Take note, the above errors repeat a few times every second, with ws_# incrementing by one each time

Unity 2018.1.1f1

Unity 2018.1.1f1

Firebase-Database:几天前获得的最新信息

Firebase-Database: Whatever is newest, got a few days ago

代码位:

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数据库的

Below is my attempt to access the firebase database

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));

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

Ruleset: (Should allow for all)

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

其他说明:

  • Firebase authentication is used and works perfectly, i just cant operate/access the database
  • Been using this as my main reference: https://firebase.google.com/docs/database/unity/save-data
  • using net 3x AND 4x, same result
  • also Mono

推荐答案

使用:

OSX Sierra 10.12.6上的Unity Editor 2018.2.5f1

Unity Editor 2018.2.5f1 on OSX Sierra 10.12.6

脚本运行时4.x

脚本后端IL2CPP

scripting backend IL2CPP

API级别4.x

Firebase插件版本5.2.1

Firebase plugin version 5.2.1

发生了同样的问题.这似乎与Mono Websocket的实现有关,如以下问题所述:

This exact same problem was happening. This seemed to be related to the Mono Websocket implementations, as discussed in more detail on the following issues:

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

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

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

The Firebase dev team went around what is described there by providing their own native websocket implementations for each platform. Apparently the Unity Editor implementation is lagging behind.

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

The way to workaround this issue here was by disabling the FirebaseDatabase.dll under ../Firebase/Plugins/Mono/ for the editor platform, and then enabling the one FirebaseDatabase.dll directly under ../Firebase/Plugins/ instead.

到目前为止,很好.

这篇关于Unity + Firebase-Database [错误] WebSocket:ws_0-无法连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆