public void Disconnect()
 {
     pushSocket?.Disconnect(pushConnectionString);
     poller?.Stop();
     poller?.Dispose();
     pushSocket?.Dispose();
 }
Ejemplo n.º 2
0
 protected override void disconnectClose()
 {
     if (sender != null)
     {
         // TODO: check first if closed
         sender.Disconnect("tcp://" + IP + ":" + Port);
         sender.Close();
         sender.Dispose();
         sender = null;
     }
     //NetMQConfig.Cleanup();
 }
 public bool Send(string message, string serverPushAddress, int serverPushPort)
 {
     try
     {
         using (var producer = new PushSocket())
         {
             producer.Connect(serverPushAddress + ":" + serverPushPort);
             producer.SendFrame(message);
             System.Threading.Thread.Sleep(2000);
             producer.Disconnect(serverPushAddress + ":" + serverPushPort);
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 4
0
        public void Client(NodeDto connectingNode,
                           DhtProtocolCommandDto protocolCommandDto)
        {
            var cleanAddress = connectingNode.IpAddress.Replace("127.0.0.1", "localhost");
            var address      = $"tcp://{cleanAddress}:{connectingNode.Port}";

            // client = _clients.FirstOrDefault(socket => socket.Options.LastEndpoint.Equals(address));
            // if (client == null)
            // {
            //     client = new RequestSocket();
            //     _clients.Add(client);
            // }

            try
            {
                client.Connect(address);
                client.TrySendFrame(protocolCommandDto.ToString());
                client?.Disconnect(address);
                // client.TryReceiveSignal(out bool signal);
            }
            catch (NetMQException e)
            {
                Log.Logger.Error(e, e.Message);
                Log.Debug(e.ErrorCode.ToString());
                Log.Debug(e.StackTrace);
                Log.Debug(e.Message);
                Console.WriteLine(e.ErrorCode);
                Console.WriteLine(e.Message);
                Console.WriteLine(e.InnerException);
                Console.WriteLine(address);
            }
            catch (Exception exception)
            {
                Log.Logger.Error(exception, exception.Message);
                Log.Debug(exception.Message);
            }
            finally
            {
                // _clients.Remove(client);
                // client?.Disconnect(address);
                // client?.Dispose();
            }
        }
Ejemplo n.º 5
0
        public void Dispose()
        {
            if (!IsRunning)
            {
                return;
            }

            _mainThread.Stop();
            _sendThread.Stop();
            _receThread.Stop();

            _pullSocket.Unbind(Address + "in");
            _pullSocket.Dispose();
            _pushSocket.Disconnect(Address + "out");
            _pushSocket.Dispose();
            _netMqContext.Dispose();
            IsRunning = false;
            Logger.Trace("game server stopped");
        }