Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem connecting to websocket server on local network wit an external ip 192.168.0.xx #72

Open
metalogica opened this issue Oct 28, 2022 · 6 comments

Comments

@metalogica
Copy link

metalogica commented Oct 28, 2022

PROBLEM

Im trying to connect to a websocket server hosted on my lan at wss://192.168.0.42:6868. It doesn't require authorization.

The websocket client fails the TLS handshake if i use an external ip like wss://192.168.0.xxx:6868 but it works fine if i use wss://localhost:6868

DETAILS

I can connect via the the TUI app wscat, but when I try to connect via the Unity editor I get the following error:

Connection Error! Please double check your URL and ensure the cortex API is runningURL: wss://192.168.0.42:6868 Error: Unable to connect to the remote server
UnityEngine.Debug:LogError (object)
CortexClient:<Start>b__13_1 (string) (at Assets/Scripts/Clients/CortexClient.cs:56)
NativeWebSocket.WebSocket/<Connect>d__27:MoveNext () (at Library/PackageCache/com.endel.nativewebsocket@c5101c0776/WebSocket/WebSocket.cs:478)
UnityEngine.UnitySynchronizationContext:ExecuteTasks () (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/UnitySynchronizationContext.cs:107)

Ideally I'd like to connect to the same local web socketserver over the local network on the Unity editor, and via a compiled device in VR.

@metalogica
Copy link
Author

metalogica commented Oct 28, 2022

I used a debugger to figure out some more context, which I detail below.

// WebSocket.cs
// we crash here
await m_Socket.ConnectAsync(uri, m_CancellationToken); l.472 

Stack Trace

UNITYTLS_INTERNAL_ERROR

at System.Net.WebSockets.WebSocketHandle.ConnectAsyncCore (System.Uri uri, System.Threading.CancellationToken cancellationToken, System.Net.WebSockets.ClientWebSocketOptions options) [0x00391] in <2fe115660d9c47728edff248f3625297>:0 \n  at System.Net.WebSockets.ClientWebSocket.ConnectAsyncCore (System.Uri uri, System.Threading.CancellationToken cancellationToken) [0x000d1] in <2fe115660d9c47728edff248f3625297>:0 

 at NativeWebSocket.WebSocket.Connect () [0x001a5] in /Users/richardjarram/Documents/unity/unity-bp-physics-master/Library/PackageCache/com.endel.nativewebsocket@c5101c0776/WebSocket/WebSocket.cs:472 

Screen Shot 2022-10-28 at 3 20 13 PM

Config that does not work

Screen Shot 2022-10-28 at 3 14 19 PM
Screen Shot 2022-10-28 at 3 14 55 PM

Config that works

Screen Shot 2022-10-28 at 3 16 38 PM

Screen Shot 2022-10-28 at 3 17 09 PM

@metalogica metalogica changed the title Problem connecting to websocket server on local network Problem connecting to websocket server on local network wit an external ip 192.168.0.xx Oct 28, 2022
@endel
Copy link
Owner

endel commented Oct 28, 2022

Does it work if you try with ws instead of wss? ws://192.168.0.xxx:6868

wss means secure and it will expect a TLS certificate configured

@metalogica
Copy link
Author

unfortunately the web socket server I am accessing is a propriety application running on my local raspberry pi. just for info, its the emotiv cortex brain machine interface api.

It only uses wss:// and there is no config for ws://.

@metalogica
Copy link
Author

metalogica commented Oct 28, 2022

Do you think it could be related to certificate parsing in the websocket library?

In Unity, when I run wss://127.0.0.1:6868 I get the same connection error as before.

I have a self-signed cert for localhost but not for 127.0.0.1.

Perhaps I need to create self signed cert for the ip 192.168.0.42 (or create a hostname for it, then a cert for that) in order to get this thing running?

@metalogica
Copy link
Author

I created a self signed cert on my local machine for this service but to no avail.

@metalogica
Copy link
Author

metalogica commented Oct 28, 2022

Seems top be similar to these issues:
#1
#70

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants