Closed meridbt closed 4 years ago
Hi @meribdt please post your server and client constructors. WatsonWebsocket relies on the underlying http.sys and it has some restrictions on how connections are handled and what hostnames you listen on.
Also are you using .NET Core or Framework? Version?
Hi @jchristn,
I'm using .NET Framework 4.7.2
server is initialized as follows:
server = new WatsonWsServer(ip, port, wss); server.MessageReceived += OnMessage; server.ClientConnected += OnClientConnected; server.ClientDisconnected += OnClientDisconnected; server.Start();
Client is the 3rd party device, I can't get it's source code
I'm listening on 192.168.1.144:1234 and client has 192.168.1.111
Using netstat I see that when Watson Server is started, specified port is being listened, but attached to System proccess. When client starts, I see connection Established, but if I put the break point inside OnClientConnected handler, it never stops there.
Meanwhile, the same code with same settings is working on WinServer 2012 even without administrative rights
Is the client configured to connect to you by host name or by IP address? Reason I ask is that http.sys demands that the HTTP HOST header match exactly. I.e. if you start WatsonWebserver listening on an IP address but another machine is trying to connect by host name, it will fail. The client must be configured to connect by whatever you specify as the server name in the server constructor, unless you listen on a wildcard like “*” while running as administrator.
Also did you add the URL ACLs?
@jchristn,
Client uses the Server's IP address. And I use exact IP without wildcard on Server side No, I didn't add URL ACLs
Could you add the URL ACLs and give it a try? I have the commands in the README Section titled “Accessing from Outside Localhost”. I’ll be able to test for you later today. Thanks!
I'll try latest tomorrow afternoon and come back with the results
Thanks @meribdt I'm going to test this now between my Windows 10 machine and Mac. Cheers
You may have to run with elevated privileges when listening on an interface IP address that isn't loopback/localhost. This is due to the dependency on http.sys.
I just tested with .NET Framework 4.5.2 using my Windows 10 machine as server and my Macbook Pro as client. I had to run with elevated privileges due to listening on an external IP address. A URL ACL was not required.
Wireless LAN adapter Wi-Fi:
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::94a:89bd:353a:2e4d%23
IPv4 Address. . . . . . . . . . . : 192.168.1.163
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.1
C:\Code\Watson\WatsonWebsocket\TestServer\bin\Debug\net452>TestServer
Server IP [127.0.0.1] : 192.168.1.163
Server Port [8080] : 8000
SSL (true/false) [false] :
WatsonWsServer starting on http://192.168.1.163:8000/
Command [? for help]: AcceptConnections accepted connection from 192.168.1.128:63481
AcceptConnections starting data receiver for 192.168.1.128:63481 (now 0 clients)
Client connected: 192.168.1.128:63481
Message received from 192.168.1.128:63481: hello world
?
Available commands:
? help (this menu)
q quit
cls clear screen
list list clients
send IP:PORT MESSAGE send message to client
kill IP:PORT disconnect a client
Command [? for help]: send 192.168.1.128:63481 hello back
Command [? for help]: DataReceiver client 192.168.1.128:63481 disconnected (websocket exception): The remote party closed the WebSocket connection without completing the close handshake.
Client disconnected: 192.168.1.128:63481
DataReceiver client 192.168.1.128:63481 disconnected (now 0 clients active)
On your Windows 7 test, where you were running as administrator, you had set the IP address of 192.168.1.144
in your constructor? I don't have a Windows 7 machine to test with, but it may need a URL ACL.
Also I created a simple project here (https://github.com/jchristn/watsonwebsockettest) to test. Could you see if this works on your Windows 7 instance? It spawns a server, then a client, then exchanges messages. This will at least see/verify that WatsonWebsocket is handling requests and providing bidirectional I/O.
Thanks!
@jchristn
Your test project doesn't work on my Win 7, I compiled it with Core 2.1
I get messages: Client disconnected from the server Sending message from client to server... Client disconnected from the server Sending message from client to server...
and then
System.AggregateException HResult=0x80131500 One or more errors occurred. (Value cannot be null. Arg_ParamName_Name) Source = System.Private.CoreLib
ArgumentNullException: Value cannot be null. Arg_ParamName_Name
netstat shows LISTENING port 9000 on PID 4 (System)
Weird.
I'll try to build a Win7 VM to test this. Can you get more details/data from the exception?
@jchristn
I filmed a short video -> https://www.dropbox.com/t/NFCAqEuXmigoCxNY
Thanks - I have a W7 VM up and running and reproduced. Putting VS community on it to test later today. Thanks!
@jchristn thanx for your job
My pleasure - may take a bit, quite a lot of updating to do before I can get VS2019 installed...
Ok, here's what I found, at least with Windows 7.
Websockets are NOT supported on Win7 with .NET Framework. See https://stackoverflow.com/questions/48011763/windows-7-websocket-platformnotsupportedexception
C:\code\watsonwebsocket\Test.Client\bin\Debug\net452>test.client
Server IP: [localhost]
Server port: [9000]
Use SSL: [y/N]?
Unhandled Exception: System.PlatformNotSupportedException: The WebSocket protocol is not supported on this platform.
at System.Net.WebSockets.WebSocketHelpers.ThrowPlatformNotSupportedException_WSPC()
at System.Net.WebSockets.ClientWebSocket..ctor()
at WatsonWebsocket.WatsonWsClient..ctor(String serverIp, Int32 serverPort, Boolean ssl)
at Test.Client.Program.InitializeClient()
at Test.Client.Program.Main(String[] args)
With .NET Core 2.2, the client doesn't upgrade the connection from HTTP to websocket:
C:\code\watsonwebsocket\Test.Server\bin\Debug\netcoreapp2.2>dotnet Test.Server.dll
Server IP: [localhost]
Server port: [9000]
Use SSL: [y/N]?
[WatsonWsServer.Start] starting on http://localhost:9000/
Command [? for help]: [WatsonWsServer.AcceptConnections] non-websocket request rejected from ::1:49272
I modified the projects to build using .NET Core 3.1 (.NET Standard 2.1 for the library) and had the same result. Client would not upgrade the connection.
So it appears that Windows 7 is out of the question.
For Windows 10, can you please try again and run the server as administrator? It should work fine.
@jchristn,
I need some time to test it on Win10, I'll let you know when finished, thank you
Hi @meribdt any update? Thanks
Hi @jchristn,
My appologies for that delay.
I have run your test project 'WatsonWebsocketTest-master' on Windows 10 (2004) and even without admin rights it works as designed.
Unfortunately, in my case, the server should cover OS from 2008R2 to Win10, so I switched to Fleck, which is independent from http.sys.
Thank you for your support and your time. You did a great job!
Well, that's a bummer, but I'm glad you found a solution. Cheers @meribdt
Just checked on 3 different machines:
Watson Websocket server to be listening on port 1234
Windows Server 2012R2: OK Windows 7 (Run as User): Port not open Windows 7 (Run as Administrator): Port opened by the system process (PID 4). Data not being handled by WatsonWebsocket Windows 10: Port not open
Do you have any suggestion?