HashrateCalculator.NodeConnection.SendPacket C# (CSharp) Method

SendPacket() public method

public SendPacket ( string packetID, byte payload ) : void
packetID string
payload byte
return void
        public void SendPacket(string packetID, byte[] payload)
        {
            byte[] hash = Program.GenerateHash(payload);

            MemoryStream stream = new MemoryStream();
            BinaryWriter w = new BinaryWriter(stream);

            w.Write(mNetworkID);

            for (int i = 0; i < 12; i++)
            {
                if (i < packetID.Length)
                    w.Write((byte)packetID[i]);
                else
                    w.Write((byte)0);
            }

            // Payload len
            w.Write(payload.Length);

            // Checksum
            w.Write(hash[0]);
            w.Write(hash[1]);
            w.Write(hash[2]);
            w.Write(hash[3]);

            w.Write(payload);

            byte[] packetData = stream.ToArray();
            /*
            Console.WriteLine("Send Packet - " + packetID);
            for (int i = 0; i < packetData.Length; i++)
            {
                Console.Write("{0:X2} ", packetData[i]);
                if (i > 0 && ((i + 1) % 16) == 0)
                    Console.Write("\n");
            }
            Console.Write("\n");
            */
            mSocket.Send(packetData);
            w.Close();
        }