本文整理汇总了C#中System.Proxy.Stop方法的典型用法代码示例。如果您正苦于以下问题:C# Proxy.Stop方法的具体用法?C# Proxy.Stop怎么用?C# Proxy.Stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Proxy
的用法示例。
在下文中一共展示了Proxy.Stop方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
IPAddress ip = null;
int port = 0;
var p = new OptionSet()
.Add("a|address=", v => ip = IPAddress.Parse(v))
.Add("p|port=", v => port = int.Parse(v));
p.Parse(args);
var proxy = new Proxy
{
ListenToIp = ip,
ListenOnPort = port
};
proxy.Start();
Console.WriteLine("Proxy is started ans listening on {0}:{1}", proxy.ListenToIp, proxy.ListenOnPort);
Console.WriteLine("Press 'Q' to stop the proxy");
while (true)
{
if (Console.KeyAvailable)
{
var key = Console.ReadKey(true);
if (key.Key == ConsoleKey.Q)
{
proxy.Stop();
Console.WriteLine("Proxy is stopped");
break;
}
}
}
}
示例2: SendAndReceive
public void SendAndReceive()
{
using (var context = NetMQContext.Create())
using (var front = context.CreateRouterSocket())
using (var back = context.CreateDealerSocket())
{
front.Bind("inproc://frontend");
back.Bind("inproc://backend");
var proxy = new Proxy(front, back);
Task.Factory.StartNew(proxy.Start);
using (var client = context.CreateRequestSocket())
using (var server = context.CreateResponseSocket())
{
client.Connect("inproc://frontend");
server.Connect("inproc://backend");
client.SendFrame("hello");
Assert.AreEqual("hello", server.ReceiveFrameString());
server.SendFrame("reply");
Assert.AreEqual("reply", client.ReceiveFrameString());
}
proxy.Stop();
}
}
示例3: Main
/// <summary>
/// Entry point of the application.
/// </summary>
static void Main(string[] args)
{
try
{
IProxy prx = new Proxy();
var cli = new CommandLine(prx);
prx.LoadData();
cli.StartLoop();
prx.Stop();
}
catch(Exception ex)
{
Console.WriteLine("The program ended abnormally!");
Console.WriteLine(ex);
Console.ReadLine();
}
}
示例4: Execute
private void Execute()
{
var ip = Settings.Default.ListenIP;
var port = Settings.Default.ListenPort;
var proxy = new Proxy
{
ListenToIp = IPAddress.Parse(ip),
ListenOnPort = port
};
try
{
proxy.Start();
}
catch (Exception ex)
{
proxy.Stop();
ServiceEventLog.WriteEntry(ex.ToString(), EventLogEntryType.Error);
Logger.Log(ex);
}
}
示例5: ControlSocketObservedMessages
public void ControlSocketObservedMessages()
{
using (var context = NetMQContext.Create())
using (var front = context.CreateRouterSocket())
using (var back = context.CreateDealerSocket())
using (var controlPush = context.CreatePushSocket())
using (var controlPull = context.CreatePullSocket())
{
front.Bind("inproc://frontend");
back.Bind("inproc://backend");
controlPush.Bind("inproc://control");
controlPull.Connect("inproc://control");
var proxy = new Proxy(front, back, controlPush);
Task.Factory.StartNew(proxy.Start);
using (var client = context.CreateRequestSocket())
using (var server = context.CreateResponseSocket())
{
client.Connect("inproc://frontend");
server.Connect("inproc://backend");
client.SendFrame("hello");
Assert.AreEqual("hello", server.ReceiveFrameString());
server.SendFrame("reply");
Assert.AreEqual("reply", client.ReceiveFrameString());
}
Assert.IsNotNull(controlPull.ReceiveFrameBytes()); // receive identity
Assert.IsEmpty(controlPull.ReceiveFrameString()); // pull terminator
Assert.AreEqual("hello", controlPull.ReceiveFrameString());
Assert.IsNotNull(controlPull.ReceiveFrameBytes()); // receive identity
Assert.IsEmpty(controlPull.ReceiveFrameString()); // pull terminator
Assert.AreEqual("reply", controlPull.ReceiveFrameString());
proxy.Stop();
}
}
示例6: StoppingProxyDisengagesFunctionality
public void StoppingProxyDisengagesFunctionality()
{
using (var context = NetMQContext.Create())
using (var front = context.CreateRouterSocket())
using (var back = context.CreateDealerSocket())
{
front.Bind("inproc://frontend");
back.Bind("inproc://backend");
var proxy = new Proxy(front, back);
Task.Factory.StartNew(proxy.Start);
// Send a message through to ensure the proxy has started
using (var client = context.CreateRequestSocket())
using (var server = context.CreateResponseSocket())
{
client.Connect("inproc://frontend");
server.Connect("inproc://backend");
client.SendFrame("hello");
Assert.AreEqual("hello", server.ReceiveFrameString());
server.SendFrame("reply");
Assert.AreEqual("reply", client.ReceiveFrameString());
proxy.Stop(); // blocks until stopped
using (var poller = new Poller(front, back))
{
poller.PollTillCancelledNonBlocking();
client.SendFrame("anyone there?");
// Should no longer receive any messages
Assert.IsFalse(server.TrySkipFrame(TimeSpan.FromMilliseconds(50)));
poller.CancelAndJoin();
}
}
}
}
示例7: StartAndStopStateValidation
public void StartAndStopStateValidation()
{
using (var context = NetMQContext.Create())
using (var front = context.CreateRouterSocket())
using (var back = context.CreateDealerSocket())
{
front.Bind("inproc://frontend");
back.Bind("inproc://backend");
var proxy = new Proxy(front, back);
Task.Factory.StartNew(proxy.Start);
// Send a message through to ensure the proxy has started
using (var client = context.CreateRequestSocket())
using (var server = context.CreateResponseSocket())
{
client.Connect("inproc://frontend");
server.Connect("inproc://backend");
client.SendFrame("hello");
Assert.AreEqual("hello", server.ReceiveFrameString());
server.SendFrame("reply");
Assert.AreEqual("reply", client.ReceiveFrameString());
}
Assert.Throws<InvalidOperationException>(proxy.Start);
Assert.Throws<InvalidOperationException>(proxy.Start);
Assert.Throws<InvalidOperationException>(proxy.Start);
proxy.Stop(); // blocks until stopped
Assert.Throws<InvalidOperationException>(proxy.Stop);
}
}
示例8: StartAgainAfterStop
public void StartAgainAfterStop()
{
using (var context = NetMQContext.Create())
using (var front = context.CreateRouterSocket())
using (var back = context.CreateDealerSocket())
{
front.Bind("inproc://frontend");
back.Bind("inproc://backend");
var proxy = new Proxy(front, back);
Task.Factory.StartNew(proxy.Start);
// Send a message through to ensure the proxy has started
using (var client = context.CreateRequestSocket())
using (var server = context.CreateResponseSocket())
{
client.Connect("inproc://frontend");
server.Connect("inproc://backend");
client.Send("hello");
Assert.AreEqual("hello", server.ReceiveString());
server.Send("reply");
Assert.AreEqual("reply", client.ReceiveString());
}
proxy.Stop(); // blocks until stopped
// Start it again
Task.Factory.StartNew(proxy.Start);
// Send a message through to ensure the proxy has started
using (var client = context.CreateRequestSocket())
using (var server = context.CreateResponseSocket())
{
client.Connect("inproc://frontend");
server.Connect("inproc://backend");
client.Send("hello");
Assert.AreEqual("hello", server.ReceiveString());
server.Send("reply");
Assert.AreEqual("reply", client.ReceiveString());
}
proxy.Stop(); // blocks until stopped
}
}