public void TestSetup()
        {
            _listenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            _serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            _clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            _serverIpAddress = IPAddress.Loopback;
            var getLocalIpResult = NetworkUtilities.GetLocalIPv4Address("192.168.2.0/24");

            if (getLocalIpResult.Success)
            {
                _serverIpAddress = getLocalIpResult.Value;
            }

            _messageReceived = string.Empty;
        }
Ejemplo n.º 2
0
        public async Task InitializeAsync(string name = "AsyncFileServer")
        {
            if (IsInitialized)
            {
                return;
            }

            MyInfo.Name           = name;
            MyInfo.Platform       = Environment.OSVersion.Platform.ToServerPlatform();
            MyInfo.TransferFolder = _settings.LocalServerFolderPath;
            MyInfo.PortNumber     = _settings.LocalServerPortNumber;

            var getLocalIp =
                NetworkUtilities.GetLocalIPv4Address(_settings.LocalNetworkCidrIp);

            MyInfo.LocalIpAddress = getLocalIp.Success
                ? getLocalIp.Value
                : IPAddress.Loopback;

            var getPublicIp =
                await NetworkUtilities.GetPublicIPv4AddressAsync().ConfigureAwait(false);

            MyInfo.PublicIpAddress = getPublicIp.Success
                ? getPublicIp.Value
                : IPAddress.None;

            if (getLocalIp.Success)
            {
                MyInfo.SessionIpAddress = MyInfo.LocalIpAddress;
            }
            else if (getPublicIp.Success)
            {
                MyInfo.SessionIpAddress = MyInfo.PublicIpAddress;
            }

            IsInitialized = true;
        }