keijiro / OscJack

Lightweight C# implementation of OSC server/client
The Unlicense
465 stars 64 forks source link

Port Binding Issues - Stopping playmode does not seem to close ports #34

Open Nolram12345 opened 2 years ago

Nolram12345 commented 2 years ago

As the title describes, I have been having issues with starting playmode with OscJack (and OscJackVS) where, after ending playmode and starting it again, it would not be able to open the ports and would complain about them already being bound to. A full restart of Unity is required to work around this issue, and it is not consistent in every case - sometimes restarting works again, sometimes it does not.

Unity Version : 2021.3.0f1

keijiro commented 2 years ago

Does it reproduce with the sample project in this repository?

Nolram12345 commented 2 years ago

I have so far not being able to do such, however I have not tested extensively yet.

antoniohof commented 1 year ago

Also have this

antoniohof commented 1 year ago

OK, this happens only with certain ports that are not supposed to be used for OSC. Try changing them.

cabbibo commented 1 year ago

@antoniohof what port do you use? I have been hitting this problem very explicity, to the point where if I run anything in edit mode, I have to restart unity every time I save a file :/

Tehenauin commented 1 year ago

OK, this happens only with certain ports that are not supposed to be used for OSC. Try changing them.

As cabbibo says, can you share what ports work for you?

I am having the same problem. Is there maybe some way to close existing ports manually?

Tehenauin commented 1 year ago

OK, It was my own fault. In my case it didn't have to do anything with the port number. (I am using port 1234)

For my custom event receiver I copied the RegisterCallback() and UnregisterCallback() Logic from the OSCEventReceiver. But somehow I forgot to call the UnregisterCallback on OnDisable(). After adding that, it works fine again.

Edit: I take it back, it is still not working. It just appears quite irregularly.

cabbibo commented 1 year ago

Port number seems to not matter! however, there are some times when it seems like the callback is not being unregistered before the new callback tries to register? I've dug down into it not having a list of servers OnEnable, but still having a bound port, but can't figure out what isn't getting called...

On Tue, Mar 21, 2023 at 4:52 AM Tehenauin @.***> wrote:

OK, It was my own fault. In my case it didn't have to do anything with the port number. (I am using port 1234)

For my custom event receiver I copied the RegisterCallback() and UnregisterCallback() Logic from the OSCEventReceiver. But somehow I forgot to call the UnregisterCallback on OnDisable(). After adding that, it works fine again.

— Reply to this email directly, view it on GitHub https://github.com/keijiro/OscJack/issues/34#issuecomment-1477702709, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAG6SWRUM6JQG7ABOLNWYFTW5GI7TANCNFSM5U2J2XQQ . You are receiving this because you commented.Message ID: @.***>

-- http://cabbi.bo

cabbibo commented 1 year ago

My 'Work Around' is to just have an editor script that gives me a button that I press to reconnect whenever it disconnects ( sometimes, but not all the time when scripts save ) Its definitely strange behavoir

On Tue, Mar 21, 2023 at 7:30 AM Isaac Cohen @.***> wrote:

Port number seems to not matter! however, there are some times when it seems like the callback is not being unregistered before the new callback tries to register? I've dug down into it not having a list of servers OnEnable, but still having a bound port, but can't figure out what isn't getting called...

On Tue, Mar 21, 2023 at 4:52 AM Tehenauin @.***> wrote:

OK, It was my own fault. In my case it didn't have to do anything with the port number. (I am using port 1234)

For my custom event receiver I copied the RegisterCallback() and UnregisterCallback() Logic from the OSCEventReceiver. But somehow I forgot to call the UnregisterCallback on OnDisable(). After adding that, it works fine again.

— Reply to this email directly, view it on GitHub https://github.com/keijiro/OscJack/issues/34#issuecomment-1477702709, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAG6SWRUM6JQG7ABOLNWYFTW5GI7TANCNFSM5U2J2XQQ . You are receiving this because you commented.Message ID: @.***>

-- http://cabbi.bo

-- http://cabbi.bo

Tehenauin commented 1 year ago

I think I found a soloution.

Since unity doesn't call the servers dispose method (which is in charge of closing the running Thread), you have to do it by yourself. Easiest is probably to call it from a monobehaviours OnDestroy method. Ideally the behaviour that creates the server. For me it looks like this:

private void OnDestroy()
    {
        var server = OscMaster.GetSharedServer(currentPort);
        server?.Dispose();
    }

I hope this is the correct answer. But so far its looking good.