/// <summary> /// Sends a requestion and waits for the response /// </summary> /// <param name="req">The request to be sent to MegaMol</param> /// <param name="timeout">The timeout when the function will throw an exception</param> /// <returns>The response answer by MegaMol</returns> public Response Send(Request req, TimeSpan timeout) { if (req == null) { throw new ArgumentNullException("req"); } socket.ReceiveTimeout = timeout; socket.SendTimeout = timeout; ZFrame reqData = req.MakeZMQRequest(); if (reqData == null) { throw new ArgumentException("req seemed illegal"); } socket.Send(reqData); Response resp = null; using (ZFrame reply = socket.ReceiveFrame()) { Response r = new Response(); r.Request = req; // set request first, because that object is required to parse the answer r.fromZFrameString(reply.ReadString(Encoding.UTF8)); resp = r; } return(resp); }
public bool TryReceive(ref Response resp, ref string err) { ZError e; using (ZMessage reply = socket.ReceiveMessage(ZSocketFlags.DontWait, out e)) { if (reply != null && reply.Count > 0) { //Response r = new Response(); //r.Request = req; // set request first, because that object is required to parse the answer resp.fromZFrameString(reply[0].ReadString(Encoding.UTF8)); //resp = r; if (e != null) { err = e.Text; } return(true); } else { return(false); } } }