使用插座连接远程计算机的问题 [英] Problem to connect remote computer using socket

查看:97
本文介绍了使用插座连接远程计算机的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一台远程计算机(例如此处的客户端)具有静态IP,例如72.55.168.241,希望连接另一台具有LAN IP的远程计算机,例如192.168.1.3(已连接Internet)

客户端:(IP> 72.55.168.241)

One Remote Computer (eg. here Client) has Static Ip Like 72.55.168.241 want to connect other Remote Computer has LAN Ip like 192.168.1.3 (connected with Internet)

Client:(IP > 72.55.168.241)

private void ConnectionRemoteEndPoint()
        {
            IPAddress ipAddr;
            TcpClient tcpServer=new TcpClient();
            ipAddr = IPAddress.Parse("192.168.1.3")
            try
            {
                tcpServer.Connect(ipAddr, 2000);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
           
        }


其他连接到Internet的远程计算机(例如此处的服务器)IP是192.168.1.3(本地LAN IP).

伺服器:(IP> 192.168.1.3)


other Remote Computer (e.g here Server)IP is 192.168.1.3(Local LAN Ip) connected with Internet.

Server: (IP > 192.168.1.3)

private void AcceptRemoteEndPoint()
{
      TcpListener listener_tcp;
      TcpClient Remtcp;
      listener_tcp = new TcpListener(IPAddress.Parse(192.168.1.3), 2000);
      listener_tcp.Start();
            while (true)
            {
                Remtcp = listener_tcp.AcceptTcpClient();
            }
}


错误来自ConnectionRemoteEndPoint()函数:
错误:不允许发送或接收数据的请求,因为未连接套接字,并且(当使用sendto调用在数据报套接字上发送时)并且未提供地址.

请帮忙..


Error come from ConnectionRemoteEndPoint() function:
Error: A request to send or receive data was disallowed because the socket is not connected and ( when sending on datagram socket using sendto call)and no address was supplied.

Please Help..
thanks.

推荐答案

您不能通过套接字通过Internet连接服务器的本地LAN IP.您写了192.168.1.3(Local LAN Ip).对于服务器,如果要通过Internet使用套接字,则需要一个真实的IP.
You can not connect Local LAN IP for server through internet by socket. You wrote 192.168.1.3(Local LAN Ip). For server you need a real IP if you want to use socket through internet.


在这里查看我的答案:

使用套接字连接的问题 [
See my answer here:

Problem to connect using Socket [^].

Now, please tell me, why this question is nearly identical to that?!
You should not do that.

—SA


听起来像您需要配置路由器以接受端口2000上的传入TCP连接并将它们转发到192.168.1.3.您还需要将代码中的IP地址更改为路由器外部接口的IP地址.
sounds like you need to configure your router to accept incoming TCP connections on port 2000 and forward them to 192.168.1.3. you''ll also need to change the IP address in your code to that of the external interface of the router.


这篇关于使用插座连接远程计算机的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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