Beispiel #1
0
        /// <summary>
        /// Sends header with format:
        ///     string: Topic + "\n"
        ///     int32: size of data
        ///
        /// </summary>
        /// <param name="msgSize"></param>
        /// <returns></returns>
        protected async virtual Task SendHeader(uint msgSize)
        {
            MemoryStream stream = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(stream);

            // send topic + EoL
            writer.Write(System.Text.Encoding.ASCII.GetBytes(Topic + "\n"));

            // send msg size
            writer.Write(msgSize);

            stream.Flush();

            await _tcpServer.SendToAllAsync(stream);
        }
Beispiel #2
0
        public virtual Task Publish(JObject jsonObj)
        {
            JObject msg = new JObject();

            msg.Add("header", JObject.FromObject(new ZOPubSubHeader(Topic)));
            msg.Add("body", jsonObj);

            string outJsonString             = msg.ToString(Formatting.None) + "\n";
            ArraySegment <byte> publishArray = new ArraySegment <byte>(Encoding.ASCII.GetBytes(outJsonString));
            Task publish = _tcpServer.SendToAllAsync(publishArray);

            return(publish);
        }