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

Added remote ip and port to OscPacket and set in UDPListener. #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

johnebgood
Copy link

@johnebgood johnebgood commented Apr 19, 2023

Many OSC implementations have OSC addresses that will call back with data to the origin IP and port.
For example if I make an OSC call to address /GetCurrentValues it will return data to the address /CurrentValues on the IP and port of the sender. This makes it possible to return information about state from an OSC server based on a call.

I added remoteIPAddress and remotePort to OSCPacket which is set on the UDPListener ReceiveCallback(). This allows the ability to craft a response.

From UDPListener:ReceiveCallback():

packet = OscPacket.GetPacket(bytes);
packet.remoteIPAddress = RemoteIpEndPoint.Address.ToString();
packet.remotePort = RemoteIpEndPoint.Port;

Example callback use case:

                if (address == "/GetCurrentValues")
                {
                    // Must have at least one value passed.
                    int dummy = (int)message.Arguments[0];

                    cameraControl.Get(CameraControlProperty.Pan, out int currentPan, out var flags1);
                    cameraControl.Get(CameraControlProperty.Tilt, out int currentTilt, out var flags2);
                    cameraControl.Get(CameraControlProperty.Zoom, out int currentZoom, out var flags3);
                    cameraControl.Get(CameraControlProperty.Focus, out int currentFocus, out var flags4);

                    Console.WriteLine($"Sending Current PTZ: {currentPan} {currentTilt} {currentZoom} {currentFocus} \n");
                    Console.WriteLine($"To: {remoteIPAddress}:{remotePort}\n");

                    var responseMessage = new SharpOSC.OscMessage("/CurrentValues", currentPan, currentTilt, currentZoom, currentFocus, theDevicePath);
                    var sender = new SharpOSC.UDPSender(message.remoteIPAddress, message.remotePort);

                    sender.Send(responseMessage);
                }

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

Successfully merging this pull request may close these issues.

1 participant