Open tkluysk opened 8 years ago
Hello there,
This issue seems to be same as issue #111.
So, is your Attach to Unity
provided by UnityVS or later one?
No, we do not have UnityVS installed. Just the vanilla VS integration from Unity3D on Windows.
@tkluysk Did you manage to work the issue out?
I have both client and server running under Unity, and when attaching a debugger (either Visual Studio or MonoDevelop), existing connection is closed with status 1011 and new connection fails with status 1006. Tried patch from issue #96 but that didn't seem to change anything. Ideas?
@alvyxaz No, sorry.
In my case only the server broke under debugger, and not the client. That inspired me to do some testing and resulted in the following patch. Websockets now works for me under a debugger.
commit 94ef945450e054b400284c636e2e2142f165d1ef
Author: Tapio Rantala <tapio.rantala@fragmentproduction.fi>
Date: Wed Oct 26 15:57:15 2016 +0300
Blocking on AcceptTcpClient() is broken, block on AsyncWaitHandle.WaitOne() instead
In Unity under a debugger AcceptTcpClient gets interrupted by WSACancelBlockingCall
Unity issue ID 780580:
https://issuetracker.unity3d.com/issues/debug-running-project-with-attached-debugger-causes-socket-exception-if-socket-is-in-another-thread
diff --git a/websocket-sharp/Server/WebSocketServer.cs b/websocket-sharp/Server/WebSocketServer.cs
index 22f8c82..460cf22 100644
--- a/websocket-sharp/Server/WebSocketServer.cs
+++ b/websocket-sharp/Server/WebSocketServer.cs
@@ -762,7 +762,9 @@ namespace WebSocketSharp.Server
{
while (true) {
try {
- var cl = _listener.AcceptTcpClient ();
+ var asyncResult = _listener.BeginAcceptTcpClient (null, null);
+ asyncResult.AsyncWaitHandle.WaitOne ();
+ var cl = _listener.EndAcceptTcpClient (asyncResult);
ThreadPool.QueueUserWorkItem (
state => {
try {
@tazpa
Good catch!
We use a websocket to communicate between our Unity app (server) and a webapp. All works swell until we fire up the Visual Studio debugger ('Attach to Unity'). The websocket is summarily closed (1001), or becomes unreachable by the client.
All permutations of (re)loading app/VS debugger/Unity were tried to no avail. Tried a few different ports, too.
Any pointers welcome here, as we're back to stone age debugging!
Unity/C#:
JavaScript:
new WebSocket("ws://127.0.0.1:50081/HTML")
Error:
WebSocket connection to 'ws://127.0.0.1:50081/HTML' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED