public void testconnect() { var sessionid = Guid.NewGuid().ToString(); var version = (byte)1; var msg = new NetMQMessage(); msg.Append(new byte[] { version }); //版本号 msg.Append("action"); //动作 msg.Append(sessionid); //sessionid msg.Append(new byte[] { 61, 2, 3 }); //客户端密钥 msg.AppendEmptyFrame(); msg.Append(Encoding.UTF8.GetBytes($"c=newseed&r=false&o={++O}&uid=xxxxxx&t=123123&token={GetToken(Token)}")); //信息头 msg.Append(Encoding.UTF8.GetBytes("seed=123123")); //信息体 PushSocket.SendMultipartMessage(msg); NetMQMessage receiveMsg = null; PullSocket.TryReceiveMultipartMessage(new TimeSpan(0, 0, 0, 20), ref receiveMsg); Console.WriteLine(receiveMsg); Assert.IsNotNull(receiveMsg); Assert.AreEqual(version, receiveMsg[0].Buffer[0]); Assert.AreEqual("action", receiveMsg[1].ConvertToString()); Assert.AreEqual(sessionid, receiveMsg[2].ConvertToString()); Assert.GreaterOrEqual(receiveMsg[3].BufferSize, 1); var headers = receiveMsg[5].ConvertToString().ToQueryDic(); Assert.AreEqual(Convert.ToString((int)StatusCode.Ok), headers["code"]); }
private void SocketListener(object sender, DoWorkEventArgs e) { using (var pullSocket = new PullSocket(_host + _port)) { while (!_eternalQueueListener.CancellationPending) { NetMQMessage message = new NetMQMessage(); if (!pullSocket.TryReceiveMultipartMessage(TimeSpan.FromMilliseconds(500), ref message)) { continue; } // There should only be 1 part messages if (message.FrameCount != 1) { continue; } var payload = message[0].ConvertToString(); var packet = JsonConvert.DeserializeObject <Packet>(payload); switch (packet.Type) { case PacketType.LiveResult: var liveResultEventModel = JsonConvert.DeserializeObject <LiveResultPacket>(payload); _packetQueue.Enqueue(liveResultEventModel); break; case PacketType.BacktestResult: var backtestResultEventModel = JsonConvert.DeserializeObject <BacktestResultPacket>(payload); _packetQueue.Enqueue(backtestResultEventModel); break; case PacketType.Log: var logEventModel = JsonConvert.DeserializeObject <LogPacket>(payload); _packetQueue.Enqueue(logEventModel); break; } } pullSocket.Close(); _resetEvent.Set(); } }