示例#1
0
        // -- Listening Functionality

        // Handle listening
        protected override void ListenCallback()
        {
            base.ListenCallback();

            while (IsListening)
            {
                try
                {
                    //IP Of sender... could be anyone
                    IPEndPoint anyIP = new IPEndPoint(IPAddress.Parse(UPP_Utils.GetLocalIPAddress()), 0);
                    byte[]     data  = receiveSocket.Receive(ref anyIP);

                    // Connect to latest packet?
                    //if(anyIP != )

                    //Debug.Log("Rece sock: rece data: " + Encoding.UTF8.GetString(data));

                    OnReceivePacket(data, anyIP);
                    //Thread.Sleep(1);
                }
                catch (Exception err)
                {
                    Debug.Log(err.ToString());
                }
            }
        }
        protected override void OpenReceiveSocket(string a_remoteAddress, int a_listenPort)
        {
            receiveSocket = new TcpListener(IPAddress.Parse(UPP_Utils.GetLocalIPAddress()), a_listenPort);
            receiveSocket.Start();

            Debug.Log("Receiving Socket: " + ((IPEndPoint)receiveSocket.LocalEndpoint).Address + ":" + ((IPEndPoint)receiveSocket.LocalEndpoint).Port);
            base.OpenReceiveSocket(a_remoteAddress, a_listenPort);
        }