예제 #1
0
    // Update is called once per frame
    void Update()
    {
        Network.ProcessEvents();

        // Broadcast Packets
        BroadcastPacket bPacket;

        while (Network.ReceiveBroadcast(out bPacket))
        {
            // If not a local address
            if (!NetworkHost.IsLocalAddress(bPacket.RemoteInfo.Address))
            {
                var address = bPacket.RemoteInfo.Address;
                var port    = bPacket.RemoteInfo.Port;

                Debug.LogFormat("Broadcast Received From: {0}:{1}", address, port);

                if (KnownPeople.Contains(bPacket.RemoteInfo))
                {
                    continue;
                }
                else
                {
                    KnownPeople.Add(bPacket.RemoteInfo);

                    //
                    var textUi = GetComponent <Text>();
                    textUi.text += address + "\n";
                }
            }
        }

        // Regular Packets
        Packet packet;

        while (Network.Receive(out packet))
        {
            //
        }
    }
예제 #2
0
        private void FixedUpdate()
        {
            // Run() needs to be called first for this body to execute.
            if (IsRunning)
            {
                // Process network events ( send, receive, broadcast, etc )
                NetworkHost.ProcessEvents();

                // Process broadcast packets.
                BroadcastPacket bPacket;
                while (NetworkHost.ReceiveBroadcast(out bPacket))
                {
                    Debug.LogFormat("Received Broadcast: {0} bytes from {1}", bPacket.Data.Length, bPacket.RemoteInfo);
                }

                // Process incoming packets from remote connections.
                if (NetworkHost.ConnectionCount > 0)
                {
                    PacketQueue.GatherPackets(NetworkHost);
                }
            }
        }