public void BindAndConnect() { using (PairSocket bind = new PairSocket()) { bind.Bind("inproc://test"); Assert.That(!bind.HasOut); using (PairSocket connect = new PairSocket()) { connect.Connect("inproc://test"); Assert.That(connect.HasOut); Assert.That(bind.HasOut); Assert.That(!bind.HasIn); Assert.That(connect.TrySendFrame("Hello")); Assert.That(bind.HasIn); string message; Assert.That(bind.TryReceiveFrameString(out message)); Assert.That(message == "Hello"); } } }
private void ConnectionWork() { AsyncIO.ForceDotNet.Force(); using (var pairSocket = new PairSocket()) { pairSocket.Options.ReceiveHighWatermark = 1000; if (_createConnection) { pairSocket.Bind("tcp://*:12345"); } else { pairSocket.Connect("tcp://localhost:12345"); } //Do one more loop in-case we send out a closing msg and then cancel the connection bool flushedBuffer = true; while (!_connectionCancelled || !flushedBuffer) { string frameString; while (pairSocket.TryReceiveFrameString(out frameString)) { _incomingMessageQueue.Enqueue(frameString); } while (_outgoingMessageQueue.TryDequeue(out frameString)) { pairSocket.SendFrame(frameString); } flushedBuffer = _connectionCancelled; } pairSocket.Close(); } NetMQConfig.Cleanup(); }