void Start() { QualitySettings.vSyncCount = 0; Application.targetFrameRate = 60; _udpReceiverRx = GetComponent <UdpReceiverRx>(); myUdpSequence = _udpReceiverRx._udpSequence; myUdpSequence .ObserveOnMainThread() .Subscribe(x => { //print(x.UdpMsg); //string[] str2; //str2 = x.UdpMsg.Split(new char[] { ',' }); people_position pos = people_position.Parser.ParseFrom(System.Text.Encoding.UTF8.GetBytes(x.UdpMsg)); }) .AddTo(this); }
void Awake() { DontDestroyOnLoad(gameObject); _udpSequence = Observable.Create <UdpState>(observer => { Debug.Log(string.Format("_udpSequence thread: {0}", System.Threading.Thread.CurrentThread.ManagedThreadId)); try { myClient = new UdpClient(listenPort); } catch (SocketException ex) { observer.OnError(ex); } IPEndPoint remoteEP = null; myClient.EnableBroadcast = true; myClient.Client.ReceiveTimeout = 5000; while (!isAppQuitting) { try { remoteEP = null; people_position pos = people_position.Parser.ParseFrom(myClient.Receive(ref remoteEP)); Debug.Log("pos is :" + pos); //var receivedMsg = "hey its constant"; //var receivedMsg = System.Text.Encoding.ASCII.GetString(myClient.Receive(ref remoteEP)); //observer.OnNext(new UdpState(remoteEP, receivedMsg)); dataAvailable = true; } catch (SocketException) { dataAvailable = false; //Debug.Log("UDP::Receive timeout"); } } observer.OnCompleted(); return(null); }) .SubscribeOn(Scheduler.ThreadPool) .Publish() .RefCount(); }