//protected IEnumerator<TResponse> Request<TRequest, TResponse>(TRequest obj) //{ // var reqData = MsgPackTool.GetBytes(obj); // var resData = Coroutine<byte[]>.Start(Request(reqData)); // while (!resData.IsFinished) // yield return default(TResponse); // if (resData.Result == null) // { // yield return default(TResponse); // yield break; // } // yield return MsgPackTool.GetMsg<TResponse>(resData.Result); //} /// <summary> /// 创建请求消息 /// </summary> /// <param name="obj"></param> /// <returns></returns> private byte[] CreateRequestMsg(byte[] obj) { var requestMsg = new BaseRequestMsg() { SessionToken = SessionToken, RequestToken = BaseNetMqServer.GenerateRequestKey(), //Path.GetRandomFileName(), Data = obj, }; return(MsgPackTool.GetBytes(requestMsg)); }
public BaseZmqWorker(BaseNetMqServer server, string backendAddr, int workerIndex) { _server = server; workerSocket = new ZSocket(NetMqManager.Instance.Context, ZSocketType.REQ); workerSocket.IdentityString = string.Format("{0}-{1}", server.ServerToken, workerIndex); workerSocket.Connect(backendAddr); _workerThread = new Thread(MainLoop); _workerThread.Start(); //Coroutine2.Start(MainLoop(null)); //MainLoop(null); //ThreadPool.QueueUserWorkItem(new WaitCallback(MainLoop), null); }
ZSocket CreateSocket(out ZError error) { var socket = new ZSocket(NetMqManager.Instance.Context, ZSocketType.REQ); socket.Connect(ReqAddress); socket.IdentityString = BaseNetMqServer.GenerateKey("CLIENT"); socket.Linger = TimeSpan.FromMilliseconds(1); if (!socket.Connect(ReqAddress, out error)) { return(null); } return(socket); }