【问题标题】:URI prefix is not recognized when using WebSocket with Unity将 WebSocket 与 Unity 一起使用时无法识别 URI 前缀
【发布时间】:2017-11-06 03:04:24
【问题描述】:
using System.Net.WebSockets;
using System.Threading.Tasks;
using System.Threading;

public class Server : MonoBehaviour
{
    private string uri = "ws://localhost:4567";
    private ClientWebSocket ws;

    void Start()
    {
        ws = new ClientWebSocket();
        ws.ConnectAsync(new Uri(uri), CancellationToken.None).Wait();
    }
}

我正在使用 Unity 版本 2017.1.0b7 Personal。

我去了Edit -> Project Settings -> Player -> Inspector -> Other Settings -> Configuration并将Scripting Runtime Version设置为Experimental (.NET 4.6 Equivalent)API Compatibility Level 已变为 .NET 4.6。 之后,上面的代码在 IDE 的内置 Unity 播放器中运行良好。它确实连接到我的 localhost-ed websocket 服务器。

但是,如果我在此之后进行独立构建并创建一个带有游戏的 .app,上面的代码会产生错误:

OSXPlayer(<hostname>)</i> NotSupportedException: The URI prefix is not recognized.
  at System.Net.WebRequest.Create (System.Uri requestUri, System.Boolean useUriBase) [0x000db] in <f044fe2c9e7e4b8e91984b41f0cf0b04>:0 

为什么会这样?我该如何解决? 谢谢。

【问题讨论】:

  • 在为 iOS 构建时,我在 2017.1.0f3 中遇到了完全相同的问题。我注意到前缀是什么实际上并不重要,因为它也发生在 http 上。这似乎也一样:forums.xamarin.com/discussion/89614/…
  • 同样的问题,2017.1.0f3。

标签: c# macos unity3d websocket


【解决方案1】:

应在未来版本 2017.3.0b1 中修复。

转载于:2017.1.0p2、2017.2.0b5、2017.3.0a2

向后移植到 2017.1.1p2、2017.2.0b11 修复于:2017.3.0b1


https://issuetracker.unity3d.com/issues/dot-net-4-dot-6-ios-build-throws-notsupportedexception-when-creating-a-webrequest-via-system-dot-net-dot-webrequest-dot-create

【讨论】:

    猜你喜欢
    • 2023-03-05
    • 2020-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-26
    • 2021-09-28
    • 1970-01-01
    相关资源
    最近更新 更多