需要帮助-家庭网络上的TCP/IP服务器 [英] Need help - TCP/IP server over home network

查看:74
本文介绍了需要帮助-家庭网络上的TCP/IP服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写将以以下方式运行的服务器(和客户端)应用程序:

假设您和我俩都将我们的机器连接到同一房屋中的同一路由器.
我的服务器上运行着我的服务器,并且您的机器连接到我的服务器,并说例如传输一些文件.

我设法使它在同一台计算机上运行(即服务器和客户端都在一台计算机上),但是我无法从房屋中的任何其他计算机连接到我的计算机上的服务器.

这是我的服务器应用程序中的代码片段:

I''m trying to write a server (and client) application that will run in the following way:

Say you and I both have our machines connected to the same router in the same house.
I have my server running on my machine, and your machine connects to my server and say for example transfers some files.

I have managed to get this running on the same machine (ie server and client are both on one machine), however I have not been able to connect to the server on my machine from any other machine in the house.

Here''s a code snippet from my server application:

this.tcpListener = new TcpListener(IPAddress.Any, 3000);
this.listenThread = new Thread(new ThreadStart(ListenForClients));
this.listenThread.Start();



这是我的客户应用程序:



And here is my client application:

IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 3000);
Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);



任何帮助表示赞赏.谢谢大家.



Any help is appreciated. Thank you all in advance.

推荐答案

以地址"127.0.0.1"开头的内容只能在服务器所在的机器上运行(它是本地环回,因此在客户端计算机上使用会将其发送回客户端计算机).因此,您需要找到服务器所在计算机的IP.

如果使用正确的IP地址仍然无法正常工作,请确保您的路由器已正确配置为将其转发到服务器计算机(Google操作方法,我使用过的每个路由器都存在该方法)
Well to start with the address "127.0.0.1" will ONLY work on the machine the server is also on (it''s the local loop back, so using on a client machine will send it back to the client machine). So you will need to find the IP of the machine the server is on.

If with the proper IP address it still doesn''t work, make sure your router is properly configured to forward it to the server machine (Google how-to''s, they exist for every router I''ve worked with)


我过去的答案中的一些想法可能会对您有所帮助:
来自同一端口号的多个客户端 [通过服务器触发的自动更新程序 [
Some ideas from my past answers might help you:
Multple clients from same port Number[^],
automatic updater triggered via server[^].

—SA


尝试"127.0.0.1" IP地址时,无法从另一台计算机访问服务器计算机.仅使用本地计算机.如果在此示例(您的家庭网络)中连接到路由器,则会为您的计算机分配一个地址.例如; 192.168.2.2,192.168.2.3例如.

在您的客户端代码中尝试其中之一.
You can not access the server computer from the another machine when you''re trying the "127.0.0.1" ip address. It''s only using your local computer. If you connected to a router in this example(your home network), an address is assigned to your computer. For example; 192.168.2.2, 192.168.2.3 ex.

Try one of these in your client code.


这篇关于需要帮助-家庭网络上的TCP/IP服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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