2017-09-14 26 views
0

我正在使用從vtortola WebSocketListener,我有一些問題,拋出一個錯誤,然後關閉自己的套接字。我認爲如果我一次在套接字上請求太多數據,就會發生這種情況。我通過1個套接字傳輸多個jpeg圖像。所以我可以獲得每秒50張以上的圖片請求。有時它發生得比別人快,有時甚至根本不會。vtortola WebSocketListener不能寫在websocket

錯誤: aex.message =「無法在websocket上寫入」 aex.innerException =「寫入超時」。

我已經在一個vb.net API項目中實現了這個項目,該項目通過單個套接字返回所有圖像。對於大多數過去它的工作正常,除了這個隨機錯誤,然後關閉套接字。

錯誤被try/catch抓到然後關閉。如果我註釋掉ws.close()和ws.Dispose(),套接字仍然會自行關閉。

Private Shared Async Function HandleConnectionAsync(ws As vtortola.WebSockets.WebSocket, cancellation As CancellationToken) As Task(Of Task) 
    ' A request is made 
    Console.WriteLine("Connection " + ws.RemoteEndpoint.Port.ToString() + " opened. " + DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss")) 

    Try 
     While ws.IsConnected AndAlso Not cancellation.IsCancellationRequested 
      msg = Await ws.ReadStringAsync(cancellation).ConfigureAwait(False) 
      If msg IsNot Nothing Then 
       Using messageWriterStream As WebSocketMessageWriteStream = ws.CreateMessageWriter(WebSocketMessageType.Binary) 
        image = Await GetImage() 
        If image IsNot Nothing Then 
         Await messageWriterStream.WriteAsync(image, 0, Int(image.Length), cancellation).ConfigureAwait(False) 
        End If 
       End Using 
      End If 
     End While 
    Catch aex As Exception 
     ws.Close() 
    Finally 
     ws.Dispose() 
     Console.WriteLine("Connection " + ws.RemoteEndpoint.Port.ToString() + " closed. " + DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss")) 
    End Try 
End Function 
+0

是什麼時候,「隨機誤差」關閉套接字生成的錯誤文本?這可能從您的異常消息文本(aex.Message)中可以看出。 – JohnH

+0

更新後,不知何故,我以爲我把原來的帖子中的錯誤信息.. – user616

+0

嗨!我認爲這已經是固定的,對吧? https://github.com/vtortola/WebSocketListener/issues/115 – vtortola

回答

0

得到的回答並固定在項目本身,here