无法与 MacOS-BigSur TCP 服务器建立 TCP 连接

穆罕默德·弗内什

我正在尝试在本地连接的计算机之间建立 TCP 客户端-服务器连接(MacBook-BigSur 是运行服务器,而 Windows 10 笔记本电脑充当客户端)。为此,我使用 Visual Studio Code 运行这两个应用程序,如下所示:

在 macOS 上:

Console.WriteLine("Starting build agent...");

var listener = new TcpListener(IPAddress.Parse("127.0.0.1"), 12345);
Console.WriteLine("Build agent Started ");
listener.Start();

while (true)
{
    var fileName = $"s-{DateTime.Now.Ticks}.tar.gz";
    using (var client = listener.AcceptTcpClient())
    using (var stream = client.GetStream())
    using (var output = File.Create(fileName))
    {
        Console.WriteLine("Client connected. Starting to receive the file...");

        // read the file in chunks of 1KB
        var buffer = new byte[1024];
        int bytesRead;
        while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
        {
            output.Write(buffer, 0, bytesRead);
        }

        Console.WriteLine("Client connected. File received successfuly.");

        Console.WriteLine(Execute($"tar -xvf '{fileName}'"));
    }

}

在 Windows 上:

    var client = new TcpClient("192.168.0.109", 12345);
    Byte[] data = File.ReadAllBytes(@"D:\shared\file.tar.gz");
    NetworkStream stream = client.GetStream();
    stream.Write(data, 0, data.Length);
    Console.WriteLine("data sent.");

但是,当 Windows 客户端尝试建立连接时,它无法说:

System.Net.Internals.SocketExceptionFactory.ExtendedSocketException: 'No connection could be made because the target machine actively refused it. 192.168.0.109:12345'

请注意,在运行服务器后,我可以通过sudo lsof -i :123456在终端中使用检查来看到 Visual Studio 正在使用端口 12345 此外,我的 Mac 设备正在使用端口192.168.0.109,防火墙已禁用,我可以使用 Windows 命令提示符对其进行 ping 操作。

罗伯特

127.0.0.1 是 localhost,这意味着根据定义,服务器只能在同一主机上访问。

如果您希望服务器侦听所有接口,请不要IPAddress.Any分别指定IPAddress.IPv6Any或使用 0.0.0.0。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

无法连接到Kafka服务器的TCP套接字

无法使用go和docker连接到mysql服务器-拨打TCP 127.0.0.1:3306:连接:连接被拒绝

推送到枢纽时无法建立与端口8080的TCP连接

无法连接到服务器:拨出TCP I / O超时

无法连接到服务器:拨打tcp [:: 1]:8080:connectex:无法建立连接,因为目标计算机主动拒绝了它

使用服务的TCP连接

Laravel:Redis无法建立连接:[tcp://127.0.0.1:6379]

psql:无法连接到服务器...服务器是否在主机上运行...是否在端口5432上接受TCP / IP连接?

CF:ERR无法建立与端口8080的TCP连接:连接被拒绝

Azure VM-无法连接到侦听特定端口的TCP服务器

无法在Windows 10上运行Kubernetes(kubectl)和Minikube。无法连接到服务器:拨打tcp [:: 1]:8080:connectex:

TCP客户端程序无法连接到我的服务器

Docker for Desktop Kubernetes无法连接到服务器:拨打tcp [:: 1]:6445

无法达到单个服务器的最大TCP连接数

我无法获得客户端脚本来连接到本地服务器,TCP连接永远不会发生

与远程服务器的TCP连接

无法连接到服务器:连接被拒绝服务器是否在主机“ 127.0.0.1”上运行并接受端口5432上的TCP / IP连接?

PHP无法使用TCP连接到本地MariaDB服务器

服务用尽TCP连接

无法通过APN连接到TCP服务器

Socat无法关闭TCP连接

无法在专用网络上建立TCP连接

使用socat与irc服务器建立安全的TCP连接

TCP客户端无法连接到TCP服务器

C ++ SFML网络:无法建立TCP连接

无法连接到服务器:dial tcp accounts.google.com :443:getsockopt:操作超时

无法在外部主机的 TCP 端口中建立连接

无法连接到服务器:连接被拒绝 服务器是否在主机上运行...并在端口 5432 上接受 TCP/IP 连接?

设置自定义 RTMP 流服务器时无法打开连接 tcp://localhost:1935