Exemple #1
0
        public ZMsg Send(AsynCtrl ctrl, ZMsg msg)
        {
            IntPtr c_msg            = C.zmsg_new();
            IEnumerator <byte[]> fe = msg.GetEnumerator();

            while (fe.MoveNext())
            {
                IntPtr c_frame = ZMsg.ToZFramePtr(fe.Current);
                C.zmsg_push_back(c_msg, c_frame);
            }

            IntPtr c_ctrl = C.asyn_ctrl_new(ctrl.Service, ctrl.Token, ctrl.Timeout, ctrl.PeerId, ctrl.MessageId);
            IntPtr res    = C.zbuscli_send(this.connection.Handle, c_ctrl, c_msg);

            C.asyn_ctrl_destroy(out c_ctrl);

            if (res == IntPtr.Zero)
            {
                throw new ZBusException("send timeout");
            }

            ZMsg result = null;

            if (res != IntPtr.Zero)
            {
                result = ZMsg.ToZMsg(res);
            }

            return(result);
        }
Exemple #2
0
        public ZMsg Request(string service, string token, ZMsg msg, int timeout = 2500)
        {
            IntPtr c_msg            = C.zmsg_new();
            IEnumerator <byte[]> fe = msg.GetEnumerator();

            while (fe.MoveNext())
            {
                IntPtr c_frame = ZMsg.ToZFramePtr(fe.Current);
                C.zmsg_push_back(c_msg, c_frame);
            }

            IntPtr res = C.zbuscli_request(this.connection.Handle, service, token, c_msg, timeout);

            if (res == IntPtr.Zero)
            {
                throw new ZBusException("request timeout");
            }

            ZMsg result = null;

            if (res != IntPtr.Zero)
            {
                result = ZMsg.ToZMsg(res);
            }

            return(result);
        }
Exemple #3
0
        public static IntPtr ToZMsgPtr(ZMsg msg)
        {
            IntPtr zmsg             = C.zmsg_new();
            IEnumerator <byte[]> fe = msg.GetEnumerator();

            while (fe.MoveNext())
            {
                IntPtr framePtr = ToZFramePtr(fe.Current);
                C.zmsg_push_back(zmsg, framePtr);
            }

            return(zmsg);
        }
Exemple #4
0
        public int Send(ZMsg msg)
        {
            IntPtr c_msg            = C.zmsg_new();
            IEnumerator <byte[]> fe = msg.GetEnumerator();

            while (fe.MoveNext())
            {
                IntPtr c_frame = ZMsg.ToZFramePtr(fe.Current);
                C.zmsg_push_back(c_msg, c_frame);
            }
            int res = C.zbusconn_send(this._handle, c_msg);

            return(res);
        }
Exemple #5
0
        public int Route(byte[] sockId, ZMsg msg)
        {
            IntPtr c_sock           = ZMsg.ToZFramePtr(sockId);
            IntPtr c_msg            = C.zmsg_new();
            IEnumerator <byte[]> fe = msg.GetEnumerator();

            while (fe.MoveNext())
            {
                IntPtr frame = ZMsg.ToZFramePtr(fe.Current);
                C.zmsg_push_back(c_msg, frame);
            }
            int res = C.zbusconn_route(this._handle, c_sock, c_msg);

            return(res);
        }
Exemple #6
0
        public int Send(ZMsg msg)
        {
            IntPtr c_msg            = C.zmsg_new();
            IEnumerator <byte[]> fe = msg.GetEnumerator();

            while (fe.MoveNext())
            {
                IntPtr c_frame = ZMsg.ToZFramePtr(fe.Current);
                C.zmsg_push_back(c_msg, c_frame);
            }

            IntPtr c_sock_id, c_msg_id;

            c_sock_id = ZMsg.ToZFramePtr(this.RecvSockId);
            c_msg_id  = ZMsg.ToZFramePtr(this.RecvMsgId);

            C.zbuswrk_set_address(this._handle, c_sock_id, c_msg_id);

            return(C.zbuswrk_send(this.connection.Handle, this._handle, c_msg));
        }
Exemple #7
0
        public ZMsg HandleRequest(ZMsg request)
        {
            ZMsg reply = new ZMsg();

            reply.PushBack("200");
            try
            {
                IEnumerator <byte[]> fe = request.GetEnumerator();
                while (fe.MoveNext())
                {
                    string res = this.HandleJsonRequest(encoding.GetString(fe.Current));
                    reply.PushBack(encoding.GetBytes(res));
                }
            }
            catch (System.Exception ex)
            {
                reply.Clear();
                reply.PushBack("500");
                string error = string.Format("Internal Error: {0}", ex.Message);
                reply.PushBack(encoding.GetBytes(error));
            }

            return(reply);
        }