티스토리 뷰

반응형

[c#/wpf/unity/osc] udp 기반 osc 통신 방식 구현(send/receive)

 

#원본 라이브러리 경로

https://github.com/ValdemarOrn/SharpOSC

 

GitHub - ValdemarOrn/SharpOSC: Full implementation of Open Sound Control in C# .NET 3.5

Full implementation of Open Sound Control in C# .NET 3.5 - GitHub - ValdemarOrn/SharpOSC: Full implementation of Open Sound Control in C# .NET 3.5

github.com

 

 

#테스트 소스(헬퍼 라이브러리) 깃헙 경로

https://github.com/gofogo2/osc-test

 

ValdemarOrn의 SharpOSC를 재가공하여 Helper를 제작하엿습니다.

 

#ReceiverHelper 구현

 

   public class OSCReceiverHelper
    {
        private static OSCReceiverHelper _instance { get; set; }
        public static OSCReceiverHelper Instance
        {
            get
            {
                return _instance ?? (_instance = new OSCReceiverHelper());
            }
        }

        public void Start()
        {
            HandleOscPacket cb = delegate (OscPacket packet)
            {
                var msg = ((OscMessage)packet).Arguments[0].ToString();
                Console.WriteLine(msg);
            }; 
            var l1 = new UDPListener(10001, cb);
        }
    }

 

 

#SenderHelper 구현

public class OSCSenderHelper
    {
        private static OSCSenderHelper _instance { get; set; }
        public static OSCSenderHelper Instance
        {
            get
            {
                return _instance ?? (_instance = new OSCSenderHelper());
            }
        }

        public void Send(string ip, object param)
        {
            var sender = new SharpOSC.UDPSender("192.168.0.21", 10001);
            //파라미터1:경로 파라미터2:전달값
            var msg = new SharpOSC.OscMessage("/test/", param);
            sender.Send(msg);
        }
    }

 

#osc #helper #c# #unity #wpf #winform #udp

반응형
댓글
반응형