Closed qlee01 closed 6 months ago
Small update; without try / catch I also get the head of exception (also added above): SocketException: Connection refused Rethrow as WebSocketException: Failed to open socket to 'ws://localhost:12345/buttplug' due error 'ConnectionRefused'.
Do you have intiface central up and running?
Do you have intiface central up and running?
Yes, and it works fine in editor play mode. Only in build I get the connection refused exception.
@qdot is there anything I can help with? I guess for now we need to go back to the pre intiface version.
@qlee01 Did you allow the build access through firewall (for the type of network you're on)?
@qlee01 Did you allow the build access through firewall (for the type of network you're on)?
This is a local service, and should not go through firewall I guess. Are you able to use it in builds?
This is a local service, and should not go through firewall I guess. Are you able to use it in builds?
Yeah for me it works. Are You working with the example or your own implementation? Got the latest version of intiface and are you using some recent Unity (2021 / 2022)?
I know local services shoudn't be blocked by firewall, but at the same time local Unity debugging often gets broken if you don't unblock Unity in firewall for private networks, so it might be worth a try. I did not have to unblock anything though for my client to connect.
I'm connecting through simple:
var connector = new ButtplugWebsocketConnector(new Uri("ws://localhost:12345/buttplug"));
try
{
client = new ButtplugClient("Game" + Application.version);
Log("Trying to create client");
// Set up client event handlers before we connect.
client.DeviceAdded += AddDevice;
client.DeviceRemoved += RemoveDevice;
client.ScanningFinished += ScanFinished;
await client.ConnectAsync(connector);
await client.StartScanningAsync();
}
catch (Exception e)
{
// Show alert in ui
throw;
}
This is a local service, and should not go through firewall I guess. Are you able to use it in builds?
Yeah for me it works. Are You working with the example or your own implementation? Got the latest version of intiface and are you using some recent Unity (2021 / 2022)?
I know local services shoudn't be blocked by firewall, but at the same time local Unity debugging often gets broken if you don't unblock Unity in firewall for private networks, so it might be worth a try. I did not have to unblock anything though for my client to connect.
I'm connecting through simple:
var connector = new ButtplugWebsocketConnector(new Uri("ws://localhost:12345/buttplug")); try { client = new ButtplugClient("Game" + Application.version); Log("Trying to create client"); // Set up client event handlers before we connect. client.DeviceAdded += AddDevice; client.DeviceRemoved += RemoveDevice; client.ScanningFinished += ScanFinished; await client.ConnectAsync(connector); await client.StartScanningAsync(); } catch (Exception e) { // Show alert in ui throw; }
I worked with own implementation based on the samples. And in Editor / Play mode everything works fine. Just in a regular (non development) build it does not work. That's why I am wondering how it could be a firewall issue. But I'll try again. I tried on 2021.3 LTS, but migrated to 2023 since then.
Is the editor/regular issue still breaking in 2023?
Also: Have you tried not connecting to anything in editor mode, then trying to connect only in regular mode? I'm wondering if the connection is not being dropped between the switch from editor/play, and Buttplug/initface only allows one connection at a time.
Is the editor/regular issue still breaking in 2023?
Also: Have you tried not connecting to anything in editor mode, then trying to connect only in regular mode? I'm wondering if the connection is not being dropped between the switch from editor/play, and Buttplug/initface only allows one connection at a time.
sorry for late reply, it took me some time to try again, as I need to do all the code changes to adapt to this version. I still have same issue, using Unity 2023.2.3. It works fine in Editor. In a build I don't get the error message anymore, it's just not getting to do anything. I see in the logs of Intiface that the connection was successful, but the event handler for adding device and such never get called. I also tried to not connect with Editor at all after a fresh restart, still the build does not work.
@qdot I got curious and wanted to try if the buttplug-unity project from this Github would work in build; I observed the following: 1) building with mono did work fine, buttplug did run in build 2) switching to IL2CPP leads to error Failed to resolve assembly: 'System.Threading.Tasks.Dataflow, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null' 3) after adding the missing DLL, it also works with ILCPP
So the issue seems to be related to my project, I suspect the reason are some packages which are in use and might interfere with the Async communication (during setup / finding devices), which is always a bit tricky in Unity.
After 10 hours of debugging and changing settings I found the culprit; In Unity Project Settings / Player / Others the "Managed Stripping Level" needs to be set to minimal. If is set to "Low" or higher, buttplug-unity does not work anymore. This was very hard to find and I don't know the reason, but it seems that some part of the compiled code of buttplug gets stripped to easily.
Heads up: The missing DLL is fixed in v3.0.1, which I just released.
As for stripping: We use a ton of reflection for our message serialization layer, so it makes sense that stripping might remove symbol names we depend on (this was a constant nightmare over in typescript/js also). I'll add the stripping comment to our README, though I'm hoping that doesn't conflict with optimization for IL2CPP.
I'm gonna close this out for now, please feel free to open a new bug if things are still a mess. I'm hopefully gonna be a bit mroe active on getting this updated now.
Hi, got new version (dev) now running in Unity Editor without issues; building is also possible now; however the method "ConnectAsync()" does not seem to work in build at all, and throws a lengthy exception, stacktrace follows:
SocketException: Connection refused Rethrow as WebSocketException: Failed to open socket to 'ws://localhost:12345/buttplug' due error 'ConnectionRefused'.
at Buttplug.Client.ButtplugClient.ConnectAsync (Buttplug.Client.IButtplugClientConnector connector, System.Threading.CancellationToken token) [0x00000] in <00000000000000000000000000000000>:0 at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0 at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0 at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction (System.Action action, System.Boolean allowInlining, System.Threading.Tasks.Task& currentTask) [0x00000] in <00000000000000000000000000000000>:0 at System.Threading.Tasks.Task.FinishContinuations () [0x00000] in <00000000000000000000000000000000>:0 at System.Threading.Tasks.Task.Finish (System.Boolean bUserDelegateExecuted) [0x00000] in <00000000000000000000000000000000>:0 at System.Threading.Tasks.Task.TrySetException (System.Object exceptionObject) [0x00000] in <00000000000000000000000000000000>:0 at System.Runtime.CompilerServices.AsyncTaskMethodBuilder
1[TResult].SetException (System.Exception exception) [0x00000] in <00000000000000000000000000000000>:0 at Buttplug.Client.Connectors.WebsocketConnector.ButtplugWebsocketConnector.ConnectAsync (System.Threading.CancellationToken token) [0x00000] in <00000000000000000000000000000000>:0 at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0 at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0 at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction (System.Action action, System.Boolean allowInlining, System.Threading.Tasks.Task& currentTask) [0x00000] in <00000000000000000000000000000000>:0 at System.Threading.Tasks.Task.FinishContinuations () [0x00000] in <00000000000000000000000000000000>:0 at System.Threading.Tasks.Task.Finish (System.Boolean bUserDelegateExecuted) [0x00000] in <00000000000000000000000000000000>:0 at System.Threading.Tasks.Task.TrySetException (System.Object exceptionObject) [0x00000] in <00000000000000000000000000000000>:0 at System.Runtime.CompilerServices.AsyncTaskMethodBuilder
1[TResult].SetException (System.Exception exception) [0x00000] in <00000000000000000000000000000000>:0 at vtortola.WebSockets.WebSocketClient.ConnectAsync (System.Uri address, vtortola.WebSockets.Http.Headers1[KnownHeaderT] requestHeaders, System.Threading.CancellationToken cancellation) [0x00000] in <00000000000000000000000000000000>:0 at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0 at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0 at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction (System.Action action, System.Boolean allowInlining, System.Threading.Tasks.Task& currentTask) [0x00000] in <00000000000000000000000000000000>:0 at System.Threading.Tasks.Task.FinishContinuations () [0x00000] in <00000000000000000000000000000000>:0 at System.Threading.Tasks.Task.Finish (System.Boolean bUserDelegateExecuted) [0x00000] in <00000000000000000000000000000000>:0 at System.Threading.Tasks.Task.ExecuteWithThreadLocal (System.Threading.Tasks.Task& currentTaskSlot) [0x00000] in <00000000000000000000000000000000>:0 at System.Threading.Tasks.Task.ExecuteEntry (System.Boolean bPreventDoubleExecution) [0x00000] in <00000000000000000000000000000000>:0 at System.Threading.Tasks.ThreadPoolTaskScheduler.TryExecuteTaskInline (System.Threading.Tasks.Task task, System.Boolean taskWasPreviouslyQueued) [0x00000] in <00000000000000000000000000000000>:0 at System.Threading.Tasks.TaskScheduler.TryRunInline (System.Threading.Tasks.Task task, System.Boolean taskWasPreviouslyQueued) [0x00000] in <00000000000000000000000000000000>:0 at System.Threading.Tasks.TaskContinuation.InlineIfPossibleOrElseQueue (System.Threading.Tasks.Task task, System.Boolean needsProtection) [0x00000] in <00000000000000000000000000000000>:0 at System.Threading.Tasks.StandardTaskContinuation.Run (System.Threading.Tasks.Task completedTask, System.Boolean bCanInlineContinuationTask) [0x00000] in <00000000000000000000000000000000>:0 at System.Threading.Tasks.Task.FinishContinuations () [0x00000] in <00000000000000000000000000000000>:0 at System.Threading.Tasks.Task.Finish (System.Boolean bUserDelegateExecuted) [0x00000] in <00000000000000000000000000000000>:0 at System.Threading.Tasks.Task.TrySetException (System.Object exceptionObject) [0x00000] in <00000000000000000000000000000000>:0 at System.Runtime.CompilerServices.AsyncTaskMethodBuilder
1[TResult].SetException (System.Exception exception) [0x00000] in <00000000000000000000000000000000>:0 at vtortola.WebSockets.WebSocketClient.OpenConnectionAsync (vtortola.WebSockets.WebSocketHandshake handshake, System.Threading.CancellationToken cancellation) [0x00000] in <00000000000000000000000000000000>:0 at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0 at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0 at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction (System.Action action, System.Boolean allowInlining, System.Threading.Tasks.Task& currentTask) [0x00000] in <00000000000000000000000000000000>:0 at System.Threading.Tasks.Task.FinishContinuations () [0x00000] in <00000000000000000000000000000000>:0 at System.Threading.Tasks.Task.Finish (System.Boolean bUserDelegateExecuted) [0x00000] in <00000000000000000000000000000000>:0 at System.Threading.Tasks.Task.TrySetException (System.Object exceptionObject) [0x00000] in <00000000000000000000000000000000>:0 at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[TResult].SetException (System.Exception exception) [0x00000] in <00000000000000000000000000000000>:0 at vtortola.WebSockets.Transports.Sockets.SocketTransport.ConnectAsync (System.Uri address, vtortola.WebSockets.WebSocketListenerOptions options, System.Threading.CancellationToken cancellation) [0x00000] in <00000000000000000000000000000000>:0 at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0 at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0 at vtortola.WebSockets.Tools.DelegateHelper.UnsafeQueueContinuation (System.Action continuation, System.Boolean continueOnCapturedContext, System.Boolean schedule) [0x00000] in <00000000000000000000000000000000>:0 at vtortola.WebSockets.Async.AsyncConditionSource.ResumeContinuations () [0x00000] in <00000000000000000000000000000000>:0 at System.Net.Sockets.Socket+<>c.<.cctor>b__367_6 (System.IAsyncResult ares) [0x00000] in <00000000000000000000000000000000>:0 at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00000] in <00000000000000000000000000000000>:0 --- End of stack trace from previous location where exception was thrown ---at StartServerProcessAndScan.StartButtplugIO () [0x00000] in <00000000000000000000000000000000>:0 at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0 at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0 at UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () [0x00000] in <00000000000000000000000000000000>:0 at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0