【发布时间】: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