Jump to content
The simFlight Network Forums

Best way to make browser interface with FSUIPC?


Recommended Posts

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

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 4 months later...

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 by ciccio85
Link to comment
Share on other sites

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

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 by ciccio85
  • Like 1
Link to comment
Share on other sites

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()

 

  • Thanks 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.