简体   繁体   English

我无法通过互联网连接到服务器

[英]I can't connect to my server over the internet

I can run the server on my local machine and connect to it on the same machine, but when I try to connect to it from a different computer over the internet, there is not sign of activity on my server, nor a response from the server on the computer I'm testing it on. 我可以在本地计算机上运行服务器并在同一台计算机上连接它,但是当我尝试通过Internet从另一台计算机连接到它时,我的服务器上没有活动迹象,也没有服务器的响应在我正在测试的计算机上。 I've tried both XP and Vista, turn off firewalls, opened ports, ran as admin; 我已经尝试过XP和Vista,关闭防火墙,打开端口,以admin身份运行; nothing is working. 没有任何工作。 :( :(

Here is my code that I'm using to accept an incoming connection: 这是我用来接受传入连接的代码:


int port = 3326;
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            try
            {
                TcpListener listener = new TcpListener(new IPEndPoint(IPAddress.Any, port));
                listener.Start();
                Console.WriteLine("Server established\nListening on Port: {0}\n", port);
                while (true)
                {
                    socket = listener.AcceptSocket();
                    socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, outime);
                    socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
                    socket.DontFragment = true;
                    NewConnection pxy = new NewConnection(socket);
                    Thread client = new Thread(new ThreadStart(pxy.Start));
                    client.IsBackground = true;
                    client.Start();
                }
}

I think that the problem is in your router, not your computer. 我认为问题出在您的路由器上,而不是您的计算机上。 When packets come from the Internet, it should be routed to an specific server. 当数据包来自Internet时,应将其路由到特定服务器。 You have to configure your router to redirect the traffic on port 3326 to your server. 您必须配置路由器以将端口3326上的流量重定向到您的服务器。

You've probably got something blocking the connection higher up. 您可能已经阻止了更高级别的连接。 Try connecting from another host on the LAN. 尝试从LAN上的另一台主机进行连接。 If you can do that, then the OS itself isn't firewalling the connection. 如果可以这样做,则表明操作系统本身并未对连接进行防火墙保护。

If either you or your ISP run a NAT router, then your machine probably doesn't have a publicly accessible address, in which case it's impossible to connect directly to it. 如果您或您的ISP运行NAT路由器,则您的计算机可能没有可公开访问的地址,在这种情况下,无法直接连接到该地址。

If there is no NAT router, something may still be blocking the connection upstream. 如果没有NAT路由器,则可能仍会阻止上游连接。

I am serious: Many ISPs actively work to stop you from using your home connection as a web server. 我是认真的:许多ISP都在积极工作,以阻止您将家庭连接用作Web服务器。 You might want to call them before you invest too much time. 您可能需要在花太多时间之前给他们打电话。

如果您试图在家里托管,则您的ISP可能会限制您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM