stella3d / OscCore

A performance-oriented OSC library for Unity
MIT License
156 stars 28 forks source link

Add ReInit Function for dynamic IP targets #3

Closed antpb closed 4 years ago

antpb commented 4 years ago

I was adding an input control to my project for the IP of the OscSender component and needed a way to reinitialize the client. The value of the input is sent to the component's m_IpAddress string, then it runs Setup() again.

I have a Property Output controller script that is doing the following to reinitilize the client and connect to the new IP.

public void changeOSCIP(string message)
    {
        OSCSender.m_IpAddress = message;
        OSCSender.ReInit();
    }

The input component then sends it's value to the above function when users finishes editing the input field.

One thing to note that may not be ideal, the m_IpAddress object is set public in this PR. When redefining the pubic IpAddress string, it fails to use the new IP in the setup function unless changes happen to m_IpAddress directly. Maybe I'm just doing this wrong. And maybe my controller script can just do this on it's own by setting the client null and running Setup. The IP still fails to update though. Would really appreciate any thoughts. :)

IMG_9556

antpb commented 4 years ago

@stella3d Here's a draft PR of what I'm doing with the reinit function :)

antpb commented 4 years ago

Makes total sense. I like that way better! I'll play around with it and test that the socket is closed when null. From what I remember, when I traced things backwards it seemed safe. It's crazy fast swapping between two OSC hosts!

Will set this ready to review when ready. Thanks! :)

antpb commented 4 years ago

Alrighty! I went ahead and marked ready for review. Curious what you think about Port. I imagine folks could want to change that as well at runtime. I added that to this PR as it seems in line with the changes.

Let me know what you think about the IP validation condition. I think it's okay but feel like that's the weakest part of this PR.

stella3d commented 4 years ago

oh, hell yeah, pulling and testing

antpb commented 4 years ago

Alrighty! I factored in the changes and tested in my OSC controller app. Built the app with an invalid IP address defaulted into the input field and left a debug log in the valid IP check. As expected on open no statement, and when proper IP was set, it gave the log. I also verified that Renoise successfully connected and received messages after. Yay!

Screen Shot 2020-03-15 at 6 13 27 PM