I am currently developing an application for the Hololens 2 in Unity.
This application is communicating via Websocket with a mobile device, where the Websocket Server is located.
The communication is established and works fine, I even can send pings and some data.
But at some point, the following method starts to throw an exception:
Windows.Networking.Sockets.DataWriter.StoreAsync()
which I use like this:
private async Task SendAsync(byte[] Data)
{
DataWriter dataWriter = new DataWriter(streamsocket.OutputStream);
try
{
dataWriter.WriteBytes(Data);
await dataWriter.StoreAsync(); // <- throws System.Exception
}
catch (Exception ex)
{
Debug.Log(ex.Message); // <- UnityEngine.Debug.Log: "Exception of type 'System.Exception' was thrown."
}
finally
{
dataWriter?.DetachStream();
dataWriter?.Dispose();
}
}
where the variable streamsocket is of type "Windows.Networking.Sockets.StreamWebSocket".
and here is the full callstack for when the exception is thrown
Exception of type 'System.Exception' was thrown.
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
WebSocketSharp.<SendAsyncTask>d__21:MoveNext()
System.Runtime.CompilerServices.AsyncTaskMethodBuilder:Start(TStateMachine&)
WebSocketUWP.WebSocket:Send(Byte[])
<PostToServer>d__27:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
UnityEngine.MonoBehaviour:StartCoroutine_Auto(IEnumerator)
<PostToServerAndWait>d__28:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
UnityEngine.MonoBehaviour:StartCoroutine_Auto(IEnumerator)
<>c__DisplayClass26_0:<SendMessageImplAsync>b__0()
Microsoft.MixedReality.WebRTC.Unity.Signaler:Update()
thanks for your help advance