TcpClient中的问题 [英] problem in TcpClient

查看:80
本文介绍了TcpClient中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每个人都将此代码发送到
发送

hi every one this code to
send

TcpClient tcpclnt = new TcpClient("localhost", 8001);

          NetworkStream mynetsream = tcpclnt.GetStream();
          StreamWriter myswrite = new StreamWriter(mynetsream);
          myswrite.WriteLine("Your Message senaadss");
          myswrite.Close();
          mynetsream.Close();
          tcpclnt.Close();
          Console.Write(tcpclnt .Connected .ToString ());
          Console.Read();



并收到



and this to receive

            mylistener = new TcpListener(8001);

             mylistener.Start();
             System.Timers.Timer aTimer = new System.Timers.Timer();
             aTimer.Elapsed += new ElapsedEventHandler(x);
             // Set the Interval to 5 seconds.
             aTimer.Interval = 5000;
             aTimer.Enabled = true;
           Console.Read();
static void x(object source, ElapsedEventArgs e)
       {


           Socket mysocket; StreamReader str;

           while (true)
           {
               mysocket = mylistener.AcceptSocket();
               myntl = new NetworkStream(mysocket);
               str = new StreamReader(myntl);
               Console.WriteLine(str.ReadToEnd());
               Console.Read();
           }

       }


在本地网络中工作
但我想在Internet上发布,何时将localhost替换为IP
我有错误
这个

o可以建立连接,因为目标计算机主动拒绝了它,而我的ip:port拒绝了吗?
感谢您的帮助
PS>我没有真正的ip


is working in local network
but i want publish on internet and when repalce localhost to IP
i have error
this

o connection could be made because the target machine actively refused it and my ip:port so ?
thanks for any help
PS> i don''t have real ip

推荐答案

您不能仅连接到任何远程系统,除非该系统设置为在相关端口号上接收您的通信.大多数系统都具有专门针对此类情况的安全性.
You cannot just connect to any remote system unless that system is setup to receive communications from you on the relevant port number. Most systems have security specifically to protect against this sort of thing.


这篇关于TcpClient中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆