HashrateCalculator.NodeConnection.SendVersionPacket C# (CSharp) Method

SendVersionPacket() public method

public SendVersionPacket ( ) : void
return void
        void SendVersionPacket()
        {
            IPEndPoint remote = (IPEndPoint)mSocket.RemoteEndPoint;
            IPEndPoint local = (IPEndPoint)mSocket.LocalEndPoint;

            // Send version packet
            MemoryStream stream = new MemoryStream();
            BinaryWriter w = new BinaryWriter(stream);

            // -- PAYLOAD --
            // version
            w.Write(mProtocolVersion);

            // Services
            Int64 services = 0x0000000000000001;
            w.Write(services);

            // Timestamp
            UInt64 timestamp = Program.UnixTime();
            w.Write(timestamp);

            // addr_recv
            w.Write(services);
            w.Write((UInt64)0);
            w.Write((ushort)0);
            w.Write((ushort)0xFFFF);
            byte[] remoteBytes = remote.Address.GetAddressBytes();
            w.Write(remoteBytes);
            w.Write(Program.Byteswap((short)mPort));

            // addr_from
            w.Write(services);
            w.Write((UInt64)0);
            w.Write((ushort)0);
            w.Write((ushort)0xFFFF);
            byte[] localBytes = local.Address.GetAddressBytes();
            w.Write(localBytes);
            w.Write(Program.Byteswap((short)mPort));

            // nonce
            w.Write((UInt64)0xC4ACFF3D04805523);

            // user_agent
            w.Write((byte)0xF);
            w.Write("/Satoshi:0.8.6/".ToArray());

            // start_height
            w.Write(mOwner.mCurrentHeight);

            byte[] packetData = stream.ToArray();
            SendPacket("version", packetData);
            w.Close();
        }