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

how make an osc response from the server #169

Open
systemeFriche opened this issue Jul 2, 2023 · 3 comments
Open

how make an osc response from the server #169

systemeFriche opened this issue Jul 2, 2023 · 3 comments

Comments

@systemeFriche
Copy link

I want to simulate a Beringher X32 mixing table with a python program. The idea is to command a max program with the X32 Edit software.
To initiate the communication between the X32 Edit software and my fake X32 program, I need the server to respond to the client with an OSC message, something like that :

def xinfo(unused_addr, args):
    server.answer('/xinfo', [X32_OSC_ADDRESS, 'X32-04-A0-71', 'X32', '4.06'])


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--ip",
                        default=X32_OSC_ADDRESS, help="The ip to listen on")
    parser.add_argument("--port",
                        type=int, default=X32_OSC_PORT, help="The port to listen on")
    args = parser.parse_args()

    dispatcher = Dispatcher()
    dispatcher.map("/xinfo", xinfo, "xinfo")

    server = OSCUDPServer((args.ip, args.port), dispatcher)

    print("Serving on {}".format(server.server_address))
    server.serve_forever()

Is it possible with python-osc module ? How ?
Thanks a lot.

@systemeFriche
Copy link
Author

I found this solution :

from pythonosc.udp_client import SimpleUDPClient

def xinfo(unused_addr, args):
    client_infos = server.get_request()[1]
    client_ip, client_port = client_infos[0], client_infos[1]
    client_answer = SimpleUDPClient(client_ip, client_port)  # Create client
    client_answer.send_message('/xinfo', [client_ip, 'X32-04-A0-71', 'X32', '4.06'])

Is there another solution less manual ?

@systemeFriche systemeFriche changed the title how make an osc response from a server how make an osc response from the server Jul 2, 2023
@systemeFriche
Copy link
Author

In fact, this solution doesn't work because client_answer sends message with a random source port but we need the source port of the response to be the server port. For instance :

client sends an OSC message : (64302, 127.0.0.1) -> to the server (10023, 127.0.0.1)
the server receives this message and answers it with another OSC message : (10023, 127.0.0.1) -> to the client (64302, 127.0.0.1)

With SimpleUDPClient we just specify 127.0.0.1 and 64302. We have to fix is source_port as 10023.

How to make a real response from the server ?

Thanks a lot.

@bobh66
Copy link
Contributor

bobh66 commented Aug 17, 2024

@systemeFriche take a look at the changes merged in #173 which is in the 1.9.0 release. You can send responses to incoming messages on both the client and server side.

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