Beispiel #1
0
 /// <summary>
 /// Starts receiving socket addresses of servers.
 /// </summary>
 /// <param name="region">The region of the world that you wish to find servers in.</param>
 /// <param name="callback">Called when a batch of Socket addresses are received.</param>
 /// <param name="filter">Used to set filter on the type of server required.</param>
 /// <param name="batchCount">Number of batches to fetch.-1 would return all addressess.(1 batch = 1 udppacket = 231 addressess).</param>
 /// <param name="errorCallback">Invoked in case of error.</param>
 public void GetAddresses(Region region, BatchReceivedCallback callback, IpFilter filter = null, int batchCount = 1, ErrorCallback errorCallback = null)
 {
     ThrowIfDisposed();
     StopReceiving();
     this.region   = region;
     Callback      = callback;
     ErrorCallback = errorCallback;
     BatchCount    = batchCount == -1 ? int.MaxValue : batchCount;
     this.filter   = filter;
     lastEndPoint  = null;
     Initialize();
     TaskList.First().Start();
 }
Beispiel #2
0
 protected override void Dispose(bool disposing)
 {
     if (!IsDisposed)
     {
         if (disposing)
         {
             StopReceiving();
             if (cts != null)
             {
                 cts.Dispose();
                 cts = null;
             }
             TaskList.Clear();
             Callback        = null;
             ErrorCallback   = null;
             AttemptCallback = null;
         }
         base.Dispose(disposing);
         IsDisposed = true;
     }
 }
Beispiel #3
0
        public async Task GetListTest()
        {
            var server = MasterQuery.GetServerInstance(MasterQuery.SourceServerEndPoint);
            var method = new BatchReceivedCallback(info =>
            {
                Console.WriteLine(info.Source);
                Console.WriteLine(info.IsLastBatch);
                Console.WriteLine(info.Region);
                Console.WriteLine(info.ReceivedEndpoints.Count);
                foreach (var endPoint in info.ReceivedEndpoints)
                {
                    Console.WriteLine($@"{endPoint.Address}:{endPoint.Port}");
                }
            });
            var filter = new IpFilter
            {
                AppId = Game.Left_4_Dead_2
            };

            server.GetAddresses(Region.Asia, method, filter);
            await Task.Delay(5000);
        }
Beispiel #4
0
        protected override void Dispose(bool disposing)
        {
            if (IsDisposed)
            {
                return;
            }
            if (disposing)
            {
                StopReceiving();
                if (_cts != null)
                {
                    _cts.Dispose();
                    _cts = null;
                }

                _taskList.Clear();
                _callback        = null;
                _errorCallback   = null;
                _attemptCallback = null;
            }

            base.Dispose(disposing);
            IsDisposed = true;
        }