-2

我写了一个使用 TcpListener 的程序。当我的应用程序使用 C# 程序运行时,其他应用程序和其他设备可以(从其他计算机或其他设备)连接到我的应用程序,并且我的 TcpListener 可以监听并响应它们。但是当我从我的应用程序构建 setup.exe 文件并安装它时,如果我的计算机上正在运行其他应用程序,则 TcpListener 可以侦听和响应,但如果其他应用程序正在从另一台计算机运行,则 TcpListener 无法侦听。并且其他设备也无法连接到我的应用程序。

请指导我解决我的问题。 谢谢

    TcpListener TcpListener;
    private void Form1_Load(object sender, EventArgs e)
            {
                TcpListener = new TcpListener(IPAddress.Any, 4051);
                thread = new Thread(Connection);
                thread.Start();
            }
    
    public void Connection()//accept connection
            {
                while (true)
                {
                    TcpClient tcpClient= new TcpClient();
                    TcpListener.Start();
                    tcpClient = TcpListener.AcceptTcpClient();
                        thread = new Thread(() => ConnectionFromOut(tcpClient));
                    thread.Start();
                }
            }
4

1 回答 1

0

通过设置windows防火墙,我可以解决这个问题。

于 2020-08-06T10:16:45.323 回答