예제 #1
0
    /// <summary>
    /// Add frame header to outgoing user message
    /// </summary>
    /// <param name="message">The message.</param>
    /// <param name="reload_connection">The reload_connection.</param>
    /// <returns></returns>
    private byte[] addFrameHeader(SimpleOverlayConnectionTableElement connectionTableEntry, byte[] message) {
      if (ReloadGlobals.Framing) {
        /* Add FH, manage connections */
        FramedMessageData fh_message_data = new FramedMessageData();
        fh_message_data.type = FramedMessageType.data;
        fh_message_data.sequence = connectionTableEntry.fh_sequence;

        m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_FH, String.Format("Tx FH DATA {0}", connectionTableEntry.fh_sequence));

        connectionTableEntry.fh_sent.Add(connectionTableEntry.fh_sequence++, DateTime.Now);
        return ToBytes(fh_message_data, message);
      }
      else {
        return message;
      }
    }
예제 #2
0
    public byte[] ToBytes(FramedMessageData fmdata, byte[] message) {
      MemoryStream ms = new MemoryStream();
      using (BinaryWriter writer = new BinaryWriter(ms)) {
        writer.Write((Byte)fmdata.type);
        writer.Write(System.Net.IPAddress.HostToNetworkOrder((int)fmdata.sequence));

        byte[] len_message = new byte[] {         /* 3 byte message length network ordered... sick */
                    (byte)((((UInt32)message.Length) >> 16) & 0xFF),
                    (byte)((((UInt32)message.Length) >> 8) & 0xFF),
                    (byte)((((UInt32)message.Length) >> 0) & 0xFF)
                };

        writer.Write(len_message);
        writer.Write(message);
      }
      return ms.ToArray();
    }