本文整理汇总了C#中ZmqSocket.Disconnect方法的典型用法代码示例。如果您正苦于以下问题:C# ZmqSocket.Disconnect方法的具体用法?C# ZmqSocket.Disconnect怎么用?C# ZmqSocket.Disconnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZmqSocket
的用法示例。
在下文中一共展示了ZmqSocket.Disconnect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClientThread
private void ClientThread()
{
try
{
status = 1;
context = ZmqContext.Create();
socket = context.CreateSocket(SocketType.DEALER);
window.SetProgress(5);
window.SetStatus("Contacting server...");
window.Log("Attempting connection to server...");
window.Log(" --> " + Settings.Default.ServerAddress);
bool connected = false;
{
byte[] identity = new byte[15];
new Random().NextBytes(identity);
socket.Identity = identity;
var helloMessage = new[] { (byte)MessageIdentifier.Init };
int attempt = 1;
var endpoint = Settings.Default.ServerAddress;
socket.Connect(endpoint);
socket.Send(helloMessage);
while (!connected)
{
var message = socket.ReceiveMessage(TimeSpan.FromSeconds(5));
if (message.TotalSize == 0)
{
window.Log("(" + attempt + ") Failed to connect, trying again in 5 seconds...");
}
else
{
window.Log("Received response, verifying...");
//check command value
if (message.First.Buffer[0] == (byte)MessageIdentifier.SetIdentity)
{
assignedIdentity = message.First.Buffer.Skip(1).ToArray();
window.Log("Received a new " + assignedIdentity.Length + " byte identity.");
socket.Identity = assignedIdentity;
socket.Disconnect(endpoint);
var finalSocket = context.CreateSocket(SocketType.DEALER);
socket.Dispose();
socket = finalSocket;
socket.Identity = assignedIdentity;
socket.TcpKeepalive = TcpKeepaliveBehaviour.Enable;
socket.Connect(endpoint);
socket.Send(new byte[] { (byte)MessageIdentifier.SetIdentity });
break;
}
if (message.First.Buffer[0] == (byte)MessageIdentifier.InvalidIdentity)
{
window.Log("Server responded with invalid identity. Trying again.");
}
}
attempt++;
Thread.Sleep(5000);
}
window.Log("Connected to master server after " + attempt + " attempts.");
window.SetProgress(20);
window.SetStatus("Synchronizing encryption...");
}
//We are connected!
window.Log("Waiting for encryption sequence...");
ZmqMessage msg = socket.ReceiveMessage();
if (msg.First.Buffer[0] != (byte)MessageIdentifier.BeginEncryption)
{
LogUnexpectedMessage(msg.First.Buffer);
window.Log("Crucial unexpected result, disconnecting.");
socket.Send(new byte[] { (byte)MessageIdentifier.Disconnect });
status = 0;
socket.Dispose();
context.Dispose();
return;
}
window.Log("Sending encryption key...");
byte[] encryptMsg = new byte[1 + keyHash.Length];
encryptMsg[0] = (byte)MessageIdentifier.BeginEncryption;
keyHash.CopyTo(encryptMsg, 1);
socket.Send(encryptMsg);
window.Log("Waiting for response...");
msg = socket.ReceiveMessage();
if (msg.First.Buffer[0] != (byte)MessageIdentifier.ConfirmEncryption)
{
window.Log("Invalid encryption key. Exiting...");
status = 0;
socket.Send(BuildMessage(MessageIdentifier.Disconnect, null, false));
return;
}
string salt = Encoding.UTF8.GetString(DecryptMessage(msg.First.Buffer.Skip(1).ToArray()));
heartbeat.Start();
window.Log("Connected, encrypted, beginning login.");
window.SetStatus("Logging in...");
//.........这里部分代码省略.........
示例2: Start1
private static void Start1(Object cancelationToken)
{
router = context.CreateSocket(SocketType.REQ);
router.Connect("tcp://127.0.0.1:5000");
router.ReceiveReady += new EventHandler<SocketEventArgs>(router_ReceiveReady1);
router.SendReady += new EventHandler<SocketEventArgs>(router_SendReady);
Poller poller = new Poller(new[] { router });
var token = (CancellationToken)cancelationToken;
while (!token.IsCancellationRequested)
{
poller.Poll(TimeSpan.FromMilliseconds(100));
}
router.Disconnect("tcp://127.0.0.1:5000");
}