|
|
@@ -17,6 +17,10 @@ namespace OHVDriveLogger
|
|
|
SubscriberSocket sub = null;
|
|
|
RequestSocket req = null;
|
|
|
|
|
|
+ PublisherSocket pub = null;
|
|
|
+
|
|
|
+ NetMQPoller poller = null;
|
|
|
+
|
|
|
ThreadCancel threadCancel = new ThreadCancel();
|
|
|
|
|
|
public ZmqManager()
|
|
|
@@ -24,16 +28,34 @@ namespace OHVDriveLogger
|
|
|
NetMQ.NetMQConfig.Cleanup();
|
|
|
}
|
|
|
|
|
|
- void CrateClientSocket()
|
|
|
+ public void CrateClientSocket()
|
|
|
{
|
|
|
+ //pub = new PublisherSocket();
|
|
|
+ //pub.Bind( "tcp://127.0.0.1:5565" );
|
|
|
+
|
|
|
sub = new SubscriberSocket();
|
|
|
sub.Connect( "tcp://127.0.0.1:5565" );
|
|
|
- sub.Subscribe(string.Empty); //All
|
|
|
+ sub.Subscribe(""); //All
|
|
|
|
|
|
sub.ReceiveReady += Sub_ReceiveReady;
|
|
|
|
|
|
req = new RequestSocket();
|
|
|
req.Connect( "tcp://127.0.0.1:5567" );
|
|
|
+
|
|
|
+ this.poller = new NetMQPoller { this.sub };
|
|
|
+ this.poller.RunAsync();
|
|
|
+
|
|
|
+ //this.threadCancel.AddGo( Th_SubPoller );
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Dispose()
|
|
|
+ {
|
|
|
+ this.poller.Dispose();
|
|
|
+ //this.pub.Dispose();
|
|
|
+ this.sub.Dispose();
|
|
|
+ this.req.Dispose();
|
|
|
+
|
|
|
+ this.threadCancel.Cancel();
|
|
|
}
|
|
|
|
|
|
private void Sub_ReceiveReady( object sender, NetMQ.NetMQSocketEventArgs e )
|
|
|
@@ -41,14 +63,32 @@ namespace OHVDriveLogger
|
|
|
logger.I( e.Socket.ReceiveMultipartStrings() );
|
|
|
}
|
|
|
|
|
|
- string Request(string topic )
|
|
|
+ void Th_SubPoller()
|
|
|
+ {
|
|
|
+ while ( !this.threadCancel.Canceled )
|
|
|
+ {
|
|
|
+ LockUtils.Wait( 1000 );
|
|
|
+ this.pub.SendMoreFrame( "1000" ).SendFrame( "Test" );
|
|
|
+ LockUtils.Wait( 100 );
|
|
|
+
|
|
|
+ NetMQMessage msg = new NetMQMessage();
|
|
|
+ if ( this.sub.TryReceiveMultipartMessage( TimeSpan.FromSeconds( 1 ), ref msg ) )
|
|
|
+ {
|
|
|
+ var m = msg;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public string Request(string topic )
|
|
|
{
|
|
|
this.req.SendFrame( topic );
|
|
|
|
|
|
if ( this.req.Poll( TimeSpan.FromSeconds( 5 ) ) )
|
|
|
{
|
|
|
-
|
|
|
+ return this.req.ReceiveFrameString();
|
|
|
}
|
|
|
+ else
|
|
|
+ return string.Empty;
|
|
|
}
|
|
|
}
|
|
|
}
|