joeherwig Posted September 24, 2022 Report Share Posted September 24, 2022 @Paul HentyIs it true that the Websocket Server is only able to register the ports on the hostname if it is started as Admin? If not started as admin i get the "access denied" message... Link to comment Share on other sites More sharing options...
Paul Henty Posted September 25, 2022 Report Share Posted September 25, 2022 Partly true. Certain URLs and Ports are secured by Windows. To use them, the account the application is running under needs permission. You can achieve this is two ways: 1. By running the application as Admin. 2. By giving the required permission to the current user. This is done using the following command: (You can execute this in the command window or in code using a process): netsh http add urlacl url=[URL TO REGISTER] user=[DOMAIN]\[USER OR GROUP] e.g. my PC here is call PJH. My user name is Paul. If I want to use the URL http://PJH:2048/fsuipc I would need this command: netsh http add urlacl url=http://PJH:2048/fsuipc/ user=PJH\Paul To run this command you need to be running 'as admin'. But once you've given permissions the socket server will be able to work without admin privileges. Paul 1 1 Link to comment Share on other sites More sharing options...
Manuel Lence Posted September 28, 2022 Report Share Posted September 28, 2022 Paul just updated my WEBSOCKET. Spectacular! Thanks a lot!! 1 Link to comment Share on other sites More sharing options...
ciccio85 Posted January 29, 2023 Report Share Posted January 29, 2023 (edited) Hello. Any idea on how to achieve a client using python? I tried a simple script but it does not work: import json import websocket from websocket import create_connection websocket.enableTrace(True) ws = create_connection("ws://MYIP:8384/fsuipc/") ws.send(json.dumps({"command":"about.read", "name":"about"})) result = ws.recv() print (result) ws.close() If I try that I get this response: --- request header --- GET /fsuipc/ HTTP/1.1 Upgrade: websocket Host: MYIP:8384 Origin: MYIP:8384 Sec-WebSocket-Key: nMbaFYGREah5M2uVaWU/nA== Sec-WebSocket-Version: 13 Connection: Upgrade ----------------------- --- response header --- Any suggestion? Thank you Francesco Edited January 29, 2023 by ciccio85 Link to comment Share on other sites More sharing options...
Paul Henty Posted January 30, 2023 Report Share Posted January 30, 2023 I've never used Python so I don't think I can help much. However, the response you're getting back is from the connection request: ws = create_connection("ws://MYIP:8384/fsuipc/") Maybe you need to get that response first, then send your 'about' command and get the response from that: import json import websocket from websocket import create_connection websocket.enableTrace(True) ws = create_connection("ws://MYIP:8384/fsuipc/") result = ws.recv() print (result) ws.send(json.dumps({"command":"about.read", "name":"about"})) result = ws.recv() print (result) ws.close() Paul Link to comment Share on other sites More sharing options...
ciccio85 Posted January 31, 2023 Report Share Posted January 31, 2023 (edited) Hello, the trick was to add the fsuipc protocol. Here the working script: import json import websocket from websocket import create_connection websocket.enableTrace(True) ws = create_connection("ws://MYIP/fsuipc/", subprotocols=["fsuipc"]) ws.send(json.dumps({"command":"about.read", "name":"about"})) result = ws.recv() print (result) ws.close() Edited January 31, 2023 by ciccio85 1 Link to comment Share on other sites More sharing options...
Paul Henty Posted January 31, 2023 Report Share Posted January 31, 2023 Excellent. I'm happy you got it working. Paul Link to comment Share on other sites More sharing options...
ciccio85 Posted February 5, 2023 Report Share Posted February 5, 2023 I have a complete working example that can be used to get the data using Python 3: import websocket import _thread import json import time import rel def on_message(ws, message): print(message) def on_error(ws, error): print(error) def on_close(ws, close_status_code, close_msg): print("### closed ###") def on_open(ws): print("Opened connection") request = { "command": "about.read", "name": "about" } request2 = { "command": "offsets.declare", "name": "myOffsets", "offsets": [ {"name": "altitude", "address": 0x0570, "type": "int", "size": 8}, {"name": "avionicsMaster", "address": 0x2E80, "type": "uint", "size": 4}, {"name": "heading", "address": 0x0580, "type": "uint", "size": 4}, {"name": "aircraftName", "address": 0x3D00, "type": "string", "size": 256} ] } request3 = { "command": 'offsets.read', "name": "myOffsets", "interval": 100 } if __name__ == "__main__": ws = websocket.WebSocketApp("ws://MYIP:PORT/fsuipc/", subprotocols=["fsuipc"], on_open=on_open, on_message=on_message, on_error=on_error, on_close=on_close) ws.run_forever(dispatcher=rel, reconnect=5) ws.send(json.dumps(request)) ws.send(json.dumps(request2)) ws.send(json.dumps(request3)) rel.signal(2, rel.abort) # Keyboard Interrupt rel.dispatch() 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now