/// <summary>
        /// Gets all server endpoints.
        /// </summary>
        private long GetServerEndpoints(long startTopVer, long endTopVer, IDictionary <Guid, ClientDiscoveryNode> dict)
        {
            return(DoOutInOp(ClientOp.ClusterGroupGetNodesEndpoints,
                             ctx =>
            {
                ctx.Writer.WriteLong(startTopVer);
                ctx.Writer.WriteLong(endTopVer);
            },
                             ctx =>
            {
                var s = ctx.Stream;

                var topVer = s.ReadLong();

                var addedCnt = s.ReadInt();

                for (var i = 0; i < addedCnt; i++)
                {
                    var id = BinaryUtils.ReadGuid(s);
                    var port = s.ReadInt();
                    var addresses = ctx.Reader.ReadStringCollection();

                    dict[id] = new ClientDiscoveryNode(id, port, addresses);
                }

                var removedCnt = s.ReadInt();

                for (var i = 0; i < removedCnt; i++)
                {
                    dict.Remove(BinaryUtils.ReadGuid(s));
                }

                return topVer;
            }));
        }
        private ClientSocket TryConnect(ClientDiscoveryNode node)
        {
            foreach (var addr in node.Addresses)
            {
                foreach (var ip in GetIps(addr, true))
                {
                    try
                    {
                        var ipEndpoint = new IPEndPoint(ip, node.Port);

                        var socket = new ClientSocket(_config, ipEndpoint, addr,
                                                      _config.ProtocolVersion, OnAffinityTopologyVersionChange, _marsh);

                        if (socket.ServerNodeId == node.Id)
                        {
                            return(socket);
                        }

                        _logger.Debug(
                            "Autodiscovery connection succeeded, but node id does not match: {0}, {1}. " +
                            "Expected node id: {2}. Actual node id: {3}. Connection dropped.",
                            addr, node.Port, node.Id, socket.ServerNodeId);
                    }
                    catch (SocketException socketEx)
                    {
                        // Ignore: failure to connect is expected.
                        _logger.Debug(socketEx, "Autodiscovery connection failed: {0}, {1}", addr, node.Port);
                    }
                }
            }

            return(null);
        }