Ejemplo n.º 1
0
    public IEnumerator SetReceiverThenSendTwice()
    {
        var count         = 2;
        var receivedCount = 0;
        var port          = 8888;

        try
        {
            udpReceiver = new UdpReceiver(
                IP.LocalIPAddressSync(),
                port,
                bytes =>
            {
                True(bytes.Length == 4);
                receivedCount++;
            }
                );

            // send udp data.
            udpSender = new UdpSender(IP.LocalIPAddressSync(), port);
            udpSender.Send(new byte[] { 1, 2, 3, 4 });
            udpSender.Send(new byte[] { 1, 2, 3, 4 });
        }
        catch (Exception e)
        {
            Fail(e.ToString());
        }

        yield return(WaitUntil(
                         () => count == receivedCount,
                         () => { throw new TimeoutException("failed."); }
                         ));
    }
    public void SendStart()
    {
        var osc = new MessageEncoder("start");

        osc.Add(cutName);
        osc.Add(delay);
        sender.Send(osc.Encode());
    }
Ejemplo n.º 3
0
        public void ReadyToPlay(List <IPEndPoint> iPEnds)
        {
            UdpSender  sender     = new UdpSender();
            UdpMessage messageToA = new UdpMessage("BPlayToARec", user.UserName);

            sender.Send(iPEnds[2], udpSender.GetLocalIP(), "17720", messageToA.ToString());
            UdpMessage messageToServer = new UdpMessage("BPlayToARecHoleOpened:" + otherName, user.UserName);

            sender.Send("152.136.73.240", "17722", udpSender.GetLocalIP(), "17721", messageToServer.ToString());
            voiceReceiver.Start();
        }
Ejemplo n.º 4
0
    public void SendMessage(byte[] data)
    {
#if UNITY_EDITOR
        //Debug.Log ("Sending Message: " + System.Text.Encoding.ASCII.GetString (data));
#endif
        udp.Send(data, data.Length);
    }
Ejemplo n.º 5
0
    public IEnumerator SetReceiverThenSendManyTimes()
    {
        var count         = 1000;
        var receivedCount = 0;
        var port          = 8888;

        udpReceiver = new UdpReceiver(
            IP.LocalIPAddressSync(),
            port,
            bytes =>
        {
            True(bytes.Length == 4);
            receivedCount++;
        }
            );

        // send udp data.
        udpSender = new UdpSender(IP.LocalIPAddressSync(), port);
        for (var i = 0; i < count; i++)
        {
            udpSender.Send(new byte[] { 1, 2, 3, 4 });
        }

        yield return(WaitUntil(
                         () => count == receivedCount,
                         () => { throw new TimeoutException("failed."); }
                         ));
    }
Ejemplo n.º 6
0
    void UpdateFaceFeatures()
    {
        if (skinnedMeshRenderer == null || !skinnedMeshRenderer.enabled || skinnedMeshRenderer.sharedMesh == null)
        {
            return;
        }

        //XRFaceMesh xRFaceMesh = new XRFaceMesh();
        //m_ARKitFaceSubsystem.GetFaceMesh(m_Face.trackableId, Allocator.Temp, ref xRFaceMesh);

#if UNITY_IOS && !UNITY_EDITOR
        using (var blendShapes = m_ARKitFaceSubsystem.GetBlendShapeCoefficients(m_Face.trackableId, Allocator.Temp))
        {
            Dictionary <int, float> data = new Dictionary <int, float>();
            foreach (var featureCoefficient in blendShapes)
            {
                int mappedBlendShapeIndex;
                if (m_FaceArkitBlendShapeIndexMap.TryGetValue(featureCoefficient.blendShapeLocation, out mappedBlendShapeIndex))
                {
                    if (mappedBlendShapeIndex >= 0)
                    {
                        skinnedMeshRenderer.SetBlendShapeWeight(mappedBlendShapeIndex, featureCoefficient.coefficient * coefficientScale);
                        data.Add(mappedBlendShapeIndex, featureCoefficient.coefficient);
                    }
                }
            }

            string json = MiniJSON.Json.Serialize(data);
            udpSender.Send(json);
        }
#endif
    }
Ejemplo n.º 7
0
        public void ReadyToRecord(List <IPEndPoint> iPEnds)
        {
            UdpSender  sender      = new UdpSender();
            UdpMessage messageToB1 = new UdpMessage("ARecToBPlay", user.UserName);

            sender.Send(iPEnds[3], udpSender.GetLocalIP(), "17719", messageToB1.ToString());
            UdpMessage messageToB2 = new UdpMessage("APlayToBRec", user.UserName);

            sender.Send(iPEnds[2], udpSender.GetLocalIP(), "17720", messageToB2.ToString());
            UdpMessage messageToServer = new UdpMessage("APlayToBRecHoleOpened:" + otherName, user.UserName);

            sender.Send("152.136.73.240", "17722", udpSender.GetLocalIP(), "17721", messageToServer.ToString());
            voiceReceiver.Start();
            IPEndPoint srcEndPoint = new IPEndPoint(IPAddress.Parse(udpSender.GetLocalIP()), 17719);

            voiceSender.Start(iPEnds[3], srcEndPoint);
        }
 private void RunThread()
 {
     while (!m_ThreadStop)
     {
         try {
             m_UdpSender.Send(m_PacketBuffer);
         }
         catch (Exception e) {
             HeartbeatService.ServiceEventLog.WriteEntry(e.ToString(), EventLogEntryType.Warning);
             return;
         }
         Thread.Sleep(m_Period);
     }
 }
    void Update()
    {
        var ms    = (Time.time * 1000).ToString("0000000000");
        var bytes = System.Text.Encoding.UTF8.GetBytes(ms);

        System.Buffer.BlockCopy(bytes, 0, data, 0, bytes.Length);

        if (send)
        {
            for (var i = 0; i < numData; i++)
            {
                sender.Send(data);
            }
        }
    }
        private void Run()
        {
            while (true)
            {
                Console.Out.WriteLine("Sending to address: " + ADDRESS);

                byte[]      buffer       = new byte[sizeof(uint)];
                BufferChunk packetBuffer = new BufferChunk(buffer);
                packetBuffer.SetUInt32(0, COOKIE);

                udpSender.Send(packetBuffer);

                Thread.Sleep(PERIOD);
            }
        }
Ejemplo n.º 11
0
        static void Send(SendOptions options)
        {
            string destName = options.Host + ":" + options.Port;

            Console.WriteLine("Sending to " + destName + " every " + options.Interval + "ms");

            UdpSender        sender     = null;
            Func <UdpSender> makeSender = () => new UdpSender(options.Host, options.Port, read: options.Reply, sourcePort: options.SourcePort, sourceHost: options.SourceHost);

            if (options.SourcePort != 0)
            {
                sender = makeSender();
            }

            Task.Run(() =>
            {
                while (true)
                {
                    try
                    {
                        if (options.SourcePort == 0)
                        {
                            sender = makeSender();
                        }

                        if (options.Reply)
                        {
                            sender.OnMessage = (response) =>
                            {
                                Console.WriteLine("Received reply to " + sender.LocalEndPoint.ToString() + " of " + string.Join(" ", response));
                            };
                        }

                        sender.Send(new byte[] { 72, 73 });

                        Console.WriteLine("Sent packet to " + destName + " from " + sender.LocalEndPoint.ToString());
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Error when sending packet " + e.ToString());
                    }

                    Thread.Sleep(options.Interval);
                }
            });
        }
Ejemplo n.º 12
0
        public void TestSend()
        {
            foreach (var receiver in _udpSender.UdpReceivers)
            {
                Logger.Debug("{0}:{1}", receiver.Ip, receiver.Port);
            }
            var client        = new UdpClient(UdpClientPort);
            var serverAddress = new IPEndPoint(IPAddress.Parse("127.0.0.1"), UdpServerPort);

            _udpSender.Send(new MocapFrame("root", "optitrack")
            {
                ElapsedMillis = 30,
                Latency       = 5.3f,
                Gesture       = "",
                Bodies        = new List <Body>()
                {
                    new Body()
                    {
                        BodyType = Body.EBodyType.Marker,
                        Rotation = Quaternion.Identity,
                        Centroid = Vector3.One,
                        Points   = new List <Point>()
                        {
                            new Point(-3.2f, 4.0f, 5.657f)
                            {
                                Name  = "",
                                State = ""
                            }
                        },
                        Name = "dynamite"
                    }
                }
            });
            var received = client.Receive(ref serverAddress);

            var frame = Model.Gen.MocapFrame.Parser.ParseFrom(received);

            Assert.AreEqual(5.3f, frame.Latency);

            var centroid = frame.Bodies[0].Centroid;

            Assert.AreEqual(Vector3.One, new Vector3(centroid.X, centroid.Y, centroid.Z));

            Assert.AreEqual("dynamite", frame.Bodies[0].Name);
        }
Ejemplo n.º 13
0
        private void SendSomeStuff()
        {
            UTF8Encoding utf8   = new UTF8Encoding();
            Random       random = new Random();
            int          rnd    = random.Next();

            while (true)
            {
                try
                {
                    byte[] buffer = utf8.GetBytes("My random number is: " + rnd);
                    sender.Send(new BufferChunk(buffer));

                    Thread.Sleep(3000);
                }
                catch { }
            }
        }
Ejemplo n.º 14
0
        static void Corporate(Options options)
        {
            List <int> sourcePorts = Enumerable.Range(50000, options.PortCount).Select(x => RandomPort()).Distinct().ToList();

            int portsSentTo = 0;

            sourcePorts.ForEach(sourcePort =>
            {
                try
                {
                    UdpSender sender = new UdpSender(options.DestIP, sourcePort, read: false, sourcePort: options.Port);
                    sender.Send(new byte[] { 1, 2, 3 });
                    portsSentTo++;
                }
                catch (Exception e) { }
            });
            Console.WriteLine("Send packets to " + portsSentTo + " ports");
        }
Ejemplo n.º 15
0
        async void LateUpdate()
        {
            // 如果需要同步,则发送摄影机和所有Anchor位置
            if (synchronizing)
            {
                if (!useUDP)
                {
                    if (syncClient != null)
                    {
                        if (syncClient.Running)
                        {
                            LiveMessageSynchronizeAll msg = CreateSyncMessage();
                            byte[] msgData = msg.Serialize();

                            // 记录Log
                            logManager.Log(currentLogName, msg.FormatLogString());

                            await syncClient.SendMessage(msgData);
                        }
                    }
                }
                else
                {
                    if (sender != null && sender.Running)
                    {
                        LiveMessageSynchronizeAll msg = CreateSyncMessage();
                        byte[] msgData = msg.Serialize();

                        // 记录Log
                        logManager.Log(currentLogName, msg.FormatLogString());

                        try
                        {
                            //Debug.Log("msgData length = " + msgData.Length);
                            await sender.Send(msgData);
                        }
                        catch (Exception e)
                        {
                            Debug.Log("---->" + e);
                        }
                    }
                }
            }
        }
Ejemplo n.º 16
0
    // Use this for initialization
    void Start()
    {
        // create receiver.
        udpReceiver = new UdpReceiver(
            IP.LocalIPAddressSync(),
            9339,
            bytes =>
        {
            Debug.Log("received udp data:" + Encoding.UTF8.GetString(bytes));
        }
            );

        // send data to receiver.
        udpSender = new UdpSender(
            IPAddress.Parse("127.0.0.1"),
            9339
            );

        udpSender.Send(
            Encoding.UTF8.GetBytes("hello via udp.")
            );
    }
Ejemplo n.º 17
0
 /// <summary>
 /// 初始化端口
 /// </summary>
 /// <returns>成功与否</returns>
 public bool Init()
 {
     try
     {
         UdpMessage ConnectRequestLiveRecorder = new UdpMessage("ConnectRequestLiveRecorder", userName);
         UdpMessage ConnectRequestLivePlayer   = new UdpMessage("ConnectRequestLivePlayer", userName);
         UdpMessage ConnectRequestSender       = new UdpMessage("ConnectRequestSender", userName);
         UdpMessage ConnectRequestReceiver     = new UdpMessage("ConnectRequestReceiver", userName);
         //打开各个端口
         udpSender.Send(ServerIP, 17722, LocalIP, 17719, ConnectRequestLiveRecorder.ToString());
         udpSender.Send(ServerIP, 17722, LocalIP, 17720, ConnectRequestLivePlayer.ToString());
         udpSender.Send(ServerIP, 17722, LocalIP, 17721, ConnectRequestSender.ToString());
         udpSender.Send(ServerIP, 17721, LocalIP, 17722, ConnectRequestReceiver.ToString());
         udpSender.Send(ServerIP, 17722, LocalIP, 17722, ConnectRequestReceiver.ToString());
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 18
0
        private void StartUdpSender()
        {
            _udpTaskCancelSource = new CancellationTokenSource();
            CancellationToken ct = _udpTaskCancelSource.Token;

            _udpTask = Task.Run(() =>
            {
                AutoResetEvent eventSignal = new AutoResetEvent(false);
                EventHandler <XdkIORotationEventArgs> handler = (o, p) =>
                {
                    eventSignal.Set();
                };

                try
                {
                    Xdk.RotationDataReceived += handler;
                    while (!ct.IsCancellationRequested)
                    {
                        int source = WaitHandle.WaitAny(new[] { ct.WaitHandle, eventSignal });
                        if (source == WaitHandle.WaitTimeout)
                        {
                            continue;
                        }
                        else if (source == 0)
                        {
                            break;
                        }

                        UdpSender.Send(Xdk.CalibratedRotation);
                    }
                }
                finally
                {
                    Xdk.RotationDataReceived -= handler;
                }
            }, ct);
        }
Ejemplo n.º 19
0
    public IEnumerator SetReceiverThenSend()
    {
        var received = false;
        var port     = 8888;

        udpReceiver = new UdpReceiver(
            IP.LocalIPAddressSync(),
            port,
            bytes =>
        {
            True(bytes.Length == 4);
            received = true;
        }
            );

        // send udp data.
        udpSender = new UdpSender(IP.LocalIPAddressSync(), port);
        udpSender.Send(new byte[] { 1, 2, 3, 4 });

        yield return(WaitUntil(
                         () => received,
                         () => { throw new TimeoutException("failed."); }
                         ));
    }
Ejemplo n.º 20
0
 public void Send(short universe, byte[] dmxData)
 {
     dmxToSend.Universe = universe;
     System.Buffer.BlockCopy(dmxData, 0, dmxToSend.DmxData, 0, dmxData.Length);
     UdpSender.Send(dmxToSend.ToArray(), remote);
 }
Ejemplo n.º 21
0
 /// <summary>
 /// 发送信息
 /// </summary>
 /// <param name="message">待发送信息</param>
 /// <param name="iPEndPoint">接收方地址</param>
 public void Send(UdpMessage message, IPEndPoint iPEndPoint)
 {
     udpSender.Send(iPEndPoint, ServerIP, "17721", message.ToString());
 }
Ejemplo n.º 22
0
    public IEnumerator SetReceiverThenSendManyTimesWithValidation()
    {
        var count         = 1000;
        var receivedCount = 0;
        var port          = 8888;

        try
        {
            var data = new byte[100];
            for (var i = 0; i < data.Length; i++)
            {
                data[i] = (byte)UnityEngine.Random.Range(byte.MinValue, byte.MaxValue);
            }

            // validate by hash. checking send data == received data or not.
            var md5     = MD5.Create();
            var origin  = md5.ComputeHash(data);
            var hashLen = origin.Length;

            // add hash data to head of new data.
            var newData = new byte[data.Length + hashLen];
            for (var i = 0; i < newData.Length; i++)
            {
                if (i < hashLen)
                {
                    newData[i] = origin[i];
                }
                else
                {
                    newData[i] = data[i - hashLen];
                }
            }

            udpReceiver = new UdpReceiver(
                IP.LocalIPAddressSync(),
                port,
                bytes =>
            {
                True(bytes.Length == newData.Length);

                var hash = md5.ComputeHash(bytes, hashLen, bytes.Length - hashLen);
                for (var i = 0; i < hash.Length; i++)
                {
                    True(hash[i] == bytes[i]);
                }

                receivedCount++;
            }
                );

            // send udp data.
            udpSender = new UdpSender(IP.LocalIPAddressSync(), port);
            for (var i = 0; i < count; i++)
            {
                udpSender.Send(newData);
            }
        }
        catch (Exception e)
        {
            Fail(e.ToString());
        }

        yield return(WaitUntil(
                         () => count == receivedCount,
                         () => { throw new TimeoutException("failed. receivedCount:" + receivedCount); }
                         ));
    }
Ejemplo n.º 23
0
 void SendText(string text, UdpSender sender)
 {
     sender.Send(text);
 }
Ejemplo n.º 24
0
    public void send(string oscPath)
    {
        var osc = new MessageEncoder(oscPath);

        sender.Send(osc.Encode());
    }