상속: NameServicePacket
예제 #1
0
        /// <exception cref="UnknownHostException"></exception>
        internal virtual NbtAddress[] GetNodeStatus(NbtAddress addr)
        {
            //Log.Out("NameSerciceClient.GetNodeStatus");

            int n;
            int srcHashCode;
            NodeStatusRequest  request;
            NodeStatusResponse response;

            response     = new NodeStatusResponse(addr);
            request      = new NodeStatusRequest(new Name(NbtAddress.AnyHostsName, unchecked (0x00), null));
            request.Addr = addr.GetInetAddress();
            n            = RetryCount;

            while (n-- > 0)
            {
                try
                {
                    Send(request, response, RetryTimeout);
                }
                catch (IOException ioe)
                {
                    if (_log.Level > 1)
                    {
                        Runtime.PrintStackTrace(ioe, _log);
                    }
                    throw new UnknownHostException(ioe);
                }
                if (response.Received && response.ResultCode == 0)
                {
                    srcHashCode = request.Addr.GetHashCode();
                    for (int i = 0; i < response.AddressArray.Length; i++)
                    {
                        response.AddressArray[i].HostName.SrcHashCode = srcHashCode;
                    }
                    return(response.AddressArray);
                }
            }
            throw new UnknownHostException();
        }
예제 #2
0
 /// <exception cref="UnknownHostException"></exception>
 internal virtual NbtAddress[] GetNodeStatus(NbtAddress addr)
 {
     int n;
     int srcHashCode;
     NodeStatusRequest request;
     NodeStatusResponse response;
     response = new NodeStatusResponse(addr);
     request = new NodeStatusRequest(new Name(NbtAddress.AnyHostsName, unchecked(0x00), null));
     request.Addr = addr.GetInetAddress();
     n = RetryCount;
     while (n-- > 0)
     {
         try
         {
             Send(request, response, RetryTimeout);
         }
         catch (IOException ioe)
         {
             if (_log.Level > 1)
             {
                 Runtime.PrintStackTrace(ioe, _log);
             }
             throw new UnknownHostException(ioe);
         }
         if (response.Received && response.ResultCode == 0)
         {
             srcHashCode = request.Addr.GetHashCode();
             for (int i = 0; i < response.AddressArray.Length; i++)
             {
                 response.AddressArray[i].HostName.SrcHashCode = srcHashCode;
             }
             return response.AddressArray;
         }
     }
     throw new UnknownHostException();
 }
예제 #3
0
        internal virtual NbtAddress[] GetHosts()
        {
            try
            {
                _waitResponse = false;

                byte[] bAddrBytes = laddr.GetAddressBytes();

                for (int i = 1; i <= 254; i++)
                {
                    NodeStatusRequest request;
                    NodeStatusResponse response;

                    byte[] addrBytes = {
                        bAddrBytes[0],
                        bAddrBytes[1],
                        bAddrBytes[2],
                        (byte)i
                    };

                    IPAddress addr = new IPAddress(addrBytes);

                    response = new NodeStatusResponse(new NbtAddress(NbtAddress.UnknownName,
                        addr.GetAddress(), false, 0x20));
                    request = new NodeStatusRequest(new Name(NbtAddress.AnyHostsName, unchecked(0x20), null));
                    request.Addr = addr;
                    Send(request, response, 0);
                }

            }
            catch (IOException ioe)
            {
                if (_log.Level > 1)
                {
                    Runtime.PrintStackTrace(ioe, _log);
                }
                throw new UnknownHostException(ioe);
            }

            _autoResetWaitReceive = new AutoResetEvent(false);
            _thread = new Thread(this);
            _thread.SetDaemon(true);
            _thread.Start();

            _autoResetWaitReceive.WaitOne();

            List<NbtAddress> result = new List<NbtAddress>();

            foreach (var key in _responseTable.Keys)
            {
                NodeStatusResponse resp = (NodeStatusResponse)_responseTable[key];

                if (resp.Received && resp.ResultCode == 0)
                {
                    foreach (var entry in resp.AddressArray)
                    {
                        if (entry.HostName.HexCode == 0x20)
                        {
                            result.Add(entry);
                        }
                    }
                }
            }

            _responseTable.Clear();

            _waitResponse = true;

            return result.Count > 0 ? result.ToArray() : null;
        }
예제 #4
0
        internal virtual NbtAddress[] GetHosts()
        {
            try
            {
                _waitResponse = false;

                byte[] bAddrBytes = laddr.GetAddressBytes();

                for (int i = 1; i <= 254; i++)
                {
                    NodeStatusRequest  request;
                    NodeStatusResponse response;

                    byte[] addrBytes =
                    {
                        bAddrBytes[0],
                        bAddrBytes[1],
                        bAddrBytes[2],
                        (byte)i
                    };

                    IPAddress addr = new IPAddress(addrBytes);

                    //response = new NodeStatusResponse(new NbtAddress(NbtAddress.UnknownName,
                    //    (int)addr.Address, false, 0x20));
                    response = new NodeStatusResponse(new NbtAddress(NbtAddress.UnknownName,
                                                                     BitConverter.ToInt32(addr.GetAddressBytes(), 0), false, 0x20));

                    request      = new NodeStatusRequest(new Name(NbtAddress.AnyHostsName, unchecked (0x20), null));
                    request.Addr = addr;
                    Send(request, response, 0);
                }
            }
            catch (IOException ioe)
            {
                if (_log.Level > 1)
                {
                    Runtime.PrintStackTrace(ioe, _log);
                }
                throw new UnknownHostException(ioe);
            }

            _autoResetWaitReceive = new AutoResetEvent(false);
            _thread = new Thread(this);
            _thread.SetDaemon(true);
            _thread.Start();

            _autoResetWaitReceive.WaitOne();

            List <NbtAddress> result = new List <NbtAddress>();

            foreach (var key in _responseTable.Keys)
            {
                NodeStatusResponse resp = (NodeStatusResponse)_responseTable[key];

                if (resp.Received && resp.ResultCode == 0)
                {
                    foreach (var entry in resp.AddressArray)
                    {
                        if (entry.HostName.HexCode == 0x20)
                        {
                            result.Add(entry);
                        }
                    }
                }
            }

            _responseTable.Clear();

            _waitResponse = true;

            return(result.Count > 0 ? result.ToArray() : null);
        }
예제 #5
0
        internal virtual NbtAddress[] GetHosts()
        {
            //Log.Out("NbtServiceClient.GetHosts");

            try
            {
                _waitResponse = false;

                byte[] bAddrBytes = laddr.GetAddressBytes();

                for (int i = 1; i <= 254; i++)
                {
                    //Log.Out($"NbtServiceClient.GetHosts - {i}");

                    NodeStatusRequest  request;
                    NodeStatusResponse response;

                    byte[] addrBytes =
                    {
                        bAddrBytes[0],
                        bAddrBytes[1],
                        bAddrBytes[2],
                        (byte)i
                    };

                    IPAddress addr = new IPAddress(addrBytes);

                    response = new NodeStatusResponse(
                        new NbtAddress(NbtAddress.UnknownName,
                                       BitConverter.ToInt32(addr.GetAddressBytes(), 0),
                                       false,
                                       0x20)
                        );

                    request = new NodeStatusRequest(new Name(NbtAddress.AnyHostsName,
                                                             unchecked (0x20),
                                                             null))
                    {
                        Addr = addr
                    };

                    Send(request, response, 0);
                }
            }
            catch (IOException ioe)
            {
                //Log.Out(ioe);

                if (_log.Level > 1)
                {
                    Runtime.PrintStackTrace(ioe, _log);
                }
                throw new UnknownHostException(ioe);
            }

            _autoResetWaitReceive = new AutoResetEvent(false);

            if (_thread != null)
            {
                _thread.Cancel(true);
                _thread.Dispose();
            }

            _thread = new Thread(this);
            _thread.SetDaemon(true);
            _thread.Start(true);

            _autoResetWaitReceive.WaitOne();

            var result = new List <NbtAddress>();

            foreach (var key in _responseTable.Keys)
            {
                var resp = (NodeStatusResponse)_responseTable[key];

                if (!resp.Received || resp.ResultCode != 0)
                {
                    continue;
                }

                result.AddRange(resp.AddressArray
                                .Where(entry => entry.HostName.HexCode == 0x20));
            }

            _responseTable.Clear();

            _waitResponse = true;

            return(result.Count > 0 ? result.ToArray() : null);
        }