本文整理汇总了C#中NetMQSocket.Bind方法的典型用法代码示例。如果您正苦于以下问题:C# NetMQSocket.Bind方法的具体用法?C# NetMQSocket.Bind怎么用?C# NetMQSocket.Bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetMQSocket
的用法示例。
在下文中一共展示了NetMQSocket.Bind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FeedZmQPublisher
public FeedZmQPublisher(string address, ILog log)
{
_log = log;
_context = NetMQContext.Create();
_socket = _context.CreatePushSocket();
_socket.Bind(address);
}
示例2: SetupPublisher
private void SetupPublisher()
{
Open(0);
_publisherSocket = _context.CreatePublisherSocket();
_publisherSocket.Bind(_configuration.PublisherAddress);
}
示例3: Start
public async Task Start ()
{
ThrowIfDisposed ();
var ct = cancellationTokenSource.Token;
nmqPoller = new Poller ();
nmqScheduler = new NetMQScheduler (nmqContext, nmqPoller);
nmqServer = nmqContext.CreateResponseSocket ();
nmqServer.Bind (Address.AbsoluteUri.TrimEnd ('/'));
serverTask = Task.Factory.StartNew (() => {
ct.ThrowIfCancellationRequested ();
while (true) {
if (ct.IsCancellationRequested) {
// clean up here
ct.ThrowIfCancellationRequested ();
}
var msg = nmqServer.Receive ();
var request = Request.Deserialize (msg);
var result = Handle (request);
byte[] output_buffer = result.Serialize ();
nmqServer.Send (output_buffer);
}
}, ct);
await serverTask;
}
示例4: InitZmq
private void InitZmq()
{
if (_ctx == null)
{
_ctx = NetMQContext.Create();
_socket = _ctx.CreatePublisherSocket();
var address = string.Format("{0}:{1}", _host, _port);
_socket.Bind(address);
}
}
示例5: NetMQScheduler
public NetMQScheduler(NetMQContext context, Poller poller = null)
{
m_context = context;
if (poller == null)
{
m_ownPoller = true;
m_poller = new Poller();
}
else
{
m_ownPoller = false;
m_poller = poller;
}
m_clientSockets = new ConcurrentBag<NetMQSocket>();
m_schedulerId = Interlocked.Increment(ref s_schedulerCounter);
m_address = string.Format("{0}://scheduler-{1}", NetMQ.zmq.Address.InProcProtocol, m_schedulerId);
m_serverSocket = context.CreatePullSocket();
m_serverSocket.Options.Linger = TimeSpan.Zero;
m_serverSocket.Bind(m_address);
m_currentMessageHandler = OnMessageFirstTime;
m_serverSocket.ReceiveReady += m_currentMessageHandler;
m_poller.AddSocket(m_serverSocket);
m_clientSocket = new ThreadLocal<NetMQSocket>(() =>
{
var socket = m_context.CreatePushSocket();
socket.Connect(m_address);
m_clientSockets.Add(socket);
return socket;
});
m_schedulerThread = new ThreadLocal<bool>(() => false);
if (m_ownPoller)
{
Task.Factory.StartNew(m_poller.Start, TaskCreationOptions.LongRunning);
}
}
示例6: Bind
public void Bind()
{
context = NetMQContext.Create();
if (socket != null)
{
throw new NetMQException("Attempt to set socket that was already defined. This would prevent successful dispose of the context later on (since we can no longer close all sockets).");
}
socket = context.CreateResponseSocket();
socket.Options.Linger = new TimeSpan(0, 0, 0, 1);
Trace.Assert(Protocol.ToLower().Equals("tcp"), "Only TCP is supported for now");
socket.Bind("tcp://" + Host + ":" + Port);
}
示例7: Start
// initialized sprites
void Start()
{
AsyncIO.ForceDotNet.Force();
calImages = new Sprite[10];
calImages[0] = Resources.Load<Sprite>("notargets");
calImages[1] = Resources.Load<Sprite>("targetTL");
calImages[2] = Resources.Load<Sprite>("targetTM");
calImages[3] = Resources.Load<Sprite>("targetTR");
calImages[4] = Resources.Load<Sprite>("targetML");
calImages[5] = Resources.Load<Sprite>("targetMM");
calImages[6] = Resources.Load<Sprite>("targetMR");
calImages[7] = Resources.Load<Sprite>("targetBL");
calImages[8] = Resources.Load<Sprite>("targetBM");
calImages[9] = Resources.Load<Sprite>("targetBR");
calCount = 0;
curCount = 0;
gameObject.GetComponent<Image> ().sprite = calImages [calCount];
//max coords 1180*564
transX = 0;
transY = 0;
targetPrefab = GameObject.FindGameObjectWithTag ("RaycastTarget");
targetPrefab.SetActive (false);
targetPrefab.layer = 2;//ignore raycast layer
isVisible = false;
AsyncIO.ForceDotNet.Force();
//setup sockets
//hangs????
//http://forum.unity3d.com/threads/netmq-basic.298104/
//must compile myself
//https://github.com/zeromq/netmq/issues/98
context = NetMQContext.Create ();
server = context.CreatePublisherSocket ();
server.Bind("tcp://127.0.0.1:5556");
client = context.CreateSubscriberSocket ();
client.Connect("tcp://127.0.0.1:5556");
client.Subscribe ("coord");
Debug.Log (System.Environment.Version);
/*server.SendMore("coord").Send ("200 200");
string top = client.ReceiveString ();
string message = client.ReceiveString ();
Debug.Log (message);
string[] coord = message.Split ();
transX = int.Parse (coord [0]);
transY = int.Parse (coord [1]);*/
}
示例8: Start
public void Start()
{
using (m_serverSocket = m_context.CreateResponseSocket())
{
foreach (var address in m_addresses)
{
m_log.InfoFormat("Listening on {0}", address);
m_serverSocket.Bind(address);
}
m_serverSocket.ReceiveReady += OnMessage;
m_poller = new Poller();
m_poller.AddSocket(m_serverSocket);
m_poller.Start();
}
}
示例9: ZeroMqHub
/// <summary>
/// Create a new instance of a Proxy (NetMQ.Proxy)
/// with the given sockets to serve as a front-end, a back-end, and a control socket.
/// </summary>
/// <param name="publisherAddress">the address that messages will be forwarded from</param>
/// <param name="subscriberAddress">the address that messages should be sent to</param>
/// <param name="heartbeat">the timespan at which to send HEARTBEAT messages (in milliseconds) - you can set this to zero if not needed</param>
/// <param name="control">this socket will have messages also sent to it - you can set this to null if not needed</param>
public ZeroMqHub(string publisherAddress, string subscriberAddress, int heartbeat = 0, NetMQSocket control = null)
{
_subscriberAddress = subscriberAddress;
_publisherAddress = publisherAddress;
var context = NetMQContext.Create();
_subscriber = context.CreateXSubscriberSocket();
_publisher = context.CreateXPublisherSocket();
_control = control;
if (heartbeat > 0)
{
_heartbeat = new NetMQTimer(heartbeat);
_heartbeat.Elapsed += (s, a) => _publisher.Send("HEARTBEAT");
}
Name = "XPub-XSub";
PSJobTypeName = typeof(ZeroMqHub).Name;
_subscriber.Bind(subscriberAddress);
_publisher.Bind(publisherAddress);
}
示例10: NetMQScheduler
/// <summary>
/// Create a new NetMQScheduler object within the given context, and optionally using the given poller.
/// </summary>
/// <param name="context">the NetMQContext to create this NetMQScheduler within</param>
/// <param name="poller">(optional)the Poller for this Net to use</param>
public NetMQScheduler([NotNull] NetMQContext context, [CanBeNull] Poller poller = null)
{
if (poller == null)
{
m_ownPoller = true;
m_poller = new Poller();
}
else
{
m_ownPoller = false;
m_poller = poller;
}
m_tasksQueue = new ConcurrentQueue<Task>();
m_syncObject = new object();
var schedulerId = Interlocked.Increment(ref s_schedulerCounter);
var address = string.Format("{0}://scheduler-{1}", Address.InProcProtocol, schedulerId);
m_serverSocket = context.CreatePullSocket();
m_serverSocket.Options.Linger = TimeSpan.Zero;
m_serverSocket.Bind(address);
m_currentMessageHandler = OnMessageFirstTime;
m_serverSocket.ReceiveReady += m_currentMessageHandler;
m_poller.AddSocket(m_serverSocket);
m_clientSocket = context.CreatePushSocket();
m_clientSocket.Connect(address);
m_schedulerThread = new ThreadLocal<bool>(() => false);
if (m_ownPoller)
{
m_poller.PollTillCancelledNonBlocking();
}
}
示例11: CreateServer
protected void CreateServer()
{
switch (_type)
{
case MQServerType.Response:
_serverSocket = _context.CreateResponseSocket(); break;
case MQServerType.Publisher:
_serverSocket = _context.CreatePublisherSocket(); break;
case MQServerType.Router:
_serverSocket = _context.CreateRouterSocket(); break;
case MQServerType.Stream:
_serverSocket = _context.CreateStreamSocket(); break;
case MQServerType.Push:
_serverSocket = _context.CreatePushSocket(); break;
case MQServerType.XPublisher:
_serverSocket = _context.CreateXPublisherSocket(); break;
default:
_serverSocket = _context.CreateResponseSocket(); break;
}
_serverSocket.Bind("tcp://*:" + _port);
}
示例12: NetMQScheduler
private NetMQScheduler(Poller poller, PushSocket pushSocket, PullSocket pullSocket)
{
if (poller == null)
{
m_ownPoller = true;
m_poller = new Poller();
}
else
{
m_ownPoller = false;
m_poller = poller;
}
var address = string.Format("{0}://scheduler-{1}",
Address.InProcProtocol,
Interlocked.Increment(ref s_schedulerCounter));
m_serverSocket = pullSocket;
m_serverSocket.Options.Linger = TimeSpan.Zero;
m_serverSocket.Bind(address);
m_currentMessageHandler = OnMessageFirstTime;
m_serverSocket.ReceiveReady += m_currentMessageHandler;
m_poller.AddSocket(m_serverSocket);
m_clientSocket = pushSocket;
m_clientSocket.Connect(address);
m_isSchedulerThread = new ThreadLocal<bool>(() => false);
if (m_ownPoller)
{
m_poller.PollTillCancelledNonBlocking();
}
}
示例13: Start
public void Start(NetMQContext context)
{
this.SetUpMonitorChannel(context);
this.SetUpAddSubscriberCountChannel(context);
//this should work but the forwarder device appears to be broken - it does not use XSUb and XPUB sockets
//forwarderDevice = new ForwarderDevice(context, PublishAddressServer, SubscribeAddressServer, DeviceMode.Threaded);
//forwarderDevice.FrontendSetup.Subscribe(string.Empty);
//forwarderDevice.Start();
//while (!forwarderDevice.IsRunning)
//{ }
QueueDevce = new QueueDevice(context, PubSubControlBackAddressServer, PubSubControlFrontAddressServer, DeviceMode.Threaded);
QueueDevce.Start();
//while (!QueueDevce.IsRunning)
//{
//}
this.Writeline("Control channel started");
long count = 0;
this.cancellationTokenSource = new CancellationTokenSource();
var token = this.cancellationTokenSource.Token;
Task.Run(() =>
{
using (frontend = context.CreateXSubscriberSocket())
{
using (backend = context.CreateXPublisherSocket())
{
frontend.Bind(Pipe.PublishAddressServer); ////"tcp://*:5550");
backend.Bind(Pipe.SubscribeAddressServer); ////"tcp://*:5553");
// frontend.ReceiveReady += frontend_ReceiveReady;
frontend.ReceiveReady += new EventHandler<NetMQSocketEventArgs>(FrontendReceiveReady);
backend.ReceiveReady += new EventHandler<NetMQSocketEventArgs>(BackendReceiveReady);
// this.AddSubscriberCountChannel.ReceiveReady += new EventHandler<NetMQSocketEventArgs>(AddSubscriberCountChannelReceiveReady);
using (this.poller = new Poller(new NetMQSocket[] { frontend, backend, this.AddSubscriberCountChannel }))
{
Writeline("About to start polling");
while (true)
{
poller.Start(); // .PollOnce(); .Poll(new TimeSpan(0,0,0,0,5));
Writeline("polling" + count);
count++;
if (token.IsCancellationRequested)
{
Writeline("break");
break;
}
}
}
Writeline("stopped polling and exiting");
}
}
},
token);
}
示例14: NmqResponseQueue
/// <summary>
/// Initializes a new instance of the <see cref="NmqResponseQueue"/> class.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="port">The port.</param>
internal NmqResponseQueue(NetMQContext context, int port)
{
socket = context.CreateResponseSocket();
var address = string.Format("tcp://127.0.0.1:{0}", port);
socket.Bind(address);
}
示例15: StartServer
/// <summary>
/// Starts the publishing and request servers.
/// </summary>
public void StartServer()
{
if (!ServerRunning)
{
_context = NetMQContext.Create();
//the publisher socket
_pubSocket = _context.CreatePublisherSocket();
_pubSocket.Bind("tcp://*:" + PublisherPort);
//the request socket
_reqSocket = _context.CreateSocket(ZmqSocketType.Rep);
_reqSocket.Bind("tcp://*:" + RequestPort);
_reqSocket.ReceiveReady += _reqSocket_ReceiveReady;
_poller = new Poller(new[] { _reqSocket });
Task.Factory.StartNew(_poller.Start, TaskCreationOptions.LongRunning);
}
ServerRunning = true;
}