C#如何在一个然后更多的功能中使用TcpClient?

问题描述

我有一个功能可以连接到Tcpserver。

private void Verbinden_Click(object sender,EventArgs e)
{
            try
            {
                tclientRemote = new TcpClient(Ipadresse.Text,remotePort);
                tclientListen = new TcpClient(Ipadresse.Text,listenPort);
            }
            catch
            {
                
            }
            if (tclientRemote.Connected & tclientListen.Connected)
            {
                Console.WriteLine("Works");
            }
            else
            {
                Console.WriteLine("Fail");
            }

}

输出:“作品”

现在我想在其他功能中使用此tcp连接来读取Stream。

 public void FunctionXYZ()
        {
            try
            {
                if (tclientListen.Connected)
                {
                    ListenStream = tclientRemote.GetStream();
                    ...

现在我得到一个错误

tclientRemote ”为“空”。

有一些解决办法吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)