/// <summary>
        /// Forwards requests from the frontend socket to the backend socket.
        /// </summary>
        protected override bool FrontendHandler(ZSocket sock, out ZMessage message, out ZError error)
        {
            error   = default(ZError);
            message = null;

            // receiving scope
            // STREAM: get 2 frames, identity and body
            ZMessage incoming = null;
            // IPAddress address = null;
            string address;

            if (!ReceiveMsg(sock, ref incoming, out address, out error))
            {
                return(false);
            }

            // sending scope
            // DEALER: forward
            using (incoming)
            {
                if (incoming[1].Length == 0)
                {
                    return(true);                    // Ignore the Empty one
                }

                // Prepend empty delimiter between Identity frame and Data frame
                incoming.Insert(1, new ZFrame());

                // Prepend Peer-Address
                incoming.Insert(2, new ZFrame(address));

                try
                {
                    if (!BackendSocket.Send(incoming, /* ZSocketFlags.DontWait, */ out error))
                    {
                        return(false);
                    }
                }
                finally {
                    incoming.Dismiss();
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        protected override void FrontendHandler(object sender, NetMQSocketEventArgs args)
        {
            bool more;

            do
            {
                var data = args.Socket.Receive(out more);

                if (more)
                {
                    BackendSocket.SendMore(data);
                }
                else
                {
                    BackendSocket.Send(data);
                }
            } while (more);
        }
Exemplo n.º 3
0
        /// <summary>
        /// This override of FrontendHandler receives data from the socket contained within args,
        /// and Sends it to BackendSocket.
        /// </summary>
        /// <param name="sender">unused</param>
        /// <param name="args">a NetMQSocketEventArgs that contains a Socket for receiving data from</param>
        protected override void FrontendHandler(object sender, NetMQSocketEventArgs args)
        {
            // TODO reuse a Msg instance here for performance
            bool more;

            do
            {
                var data = args.Socket.ReceiveFrameBytes(out more);

                if (more)
                {
                    BackendSocket.SendMore(data);
                }
                else
                {
                    BackendSocket.Send(data);
                }
            } while (more);
        }