Lidgren.Network.NetIncomingMessage.ReadIPEndpoint C# (CSharp) Method

ReadIPEndpoint() public method

Reads a stored IPv4 endpoint description
public ReadIPEndpoint ( ) : IPEndPoint
return System.Net.IPEndPoint
        public IPEndPoint ReadIPEndpoint()
        {
            byte len = ReadByte();
            byte[] addressBytes = ReadBytes(len);
            int port = (int)ReadUInt16();

            IPAddress address = new IPAddress(addressBytes);
            return new IPEndPoint(address, port);
        }

Usage Example

コード例 #1
0
        /// <summary>
        /// Called when host/client receives a NatIntroduction message from a master server
        /// </summary>
        private void HandleNatIntroduction(int ptr)
        {
            VerifyNetworkThread();

            // read intro
            NetIncomingMessage tmp = SetupReadHelperMessage(ptr, 1000);             // never mind length

            byte       hostByte       = tmp.ReadByte();
            IPEndPoint remoteInternal = tmp.ReadIPEndpoint();
            IPEndPoint remoteExternal = tmp.ReadIPEndpoint();
            string     token          = tmp.ReadString();
            bool       isHost         = (hostByte != 0);

            LogDebug("NAT introduction received; we are designated " + (isHost ? "host" : "client"));

            NetOutgoingMessage punch;

            if (!isHost && m_configuration.IsMessageTypeEnabled(NetIncomingMessageType.NatIntroductionSuccess) == false)
            {
                return;                 // no need to punch - we're not listening for nat intros!
            }
            // send internal punch
            punch = CreateMessage(1);
            punch.m_messageType = NetMessageType.NatPunchMessage;
            punch.Write(hostByte);
            punch.Write(token);
            m_unsentUnconnectedMessages.Enqueue(new NetTuple <IPEndPoint, NetOutgoingMessage>(remoteInternal, punch));

            // send external punch
            punch = CreateMessage(1);
            punch.m_messageType = NetMessageType.NatPunchMessage;
            punch.Write(hostByte);
            punch.Write(token);
            m_unsentUnconnectedMessages.Enqueue(new NetTuple <IPEndPoint, NetOutgoingMessage>(remoteExternal, punch));
        }
All Usage Examples Of Lidgren.Network.NetIncomingMessage::ReadIPEndpoint