简体   繁体   English

Java套接字编程

[英]Java socket programming

I am currently connecting PC with the galileo board, I am using java socket programming for connecting PC with the board,我目前正在将 PC 与伽利略板连接,我正在使用 java socket 编程将 PC 与板连接,

At the client side I need to give:在客户端,我需要提供:

Socket client = new Socket(serverName, port);

Where I will provide the IP address of the PC.我将在这里提供 PC 的 IP 地址。 But everytime I connect galileo board to a different PC, I need to go into the code and modify the IP address.但是每次我将伽利略板连接到不同的 PC 时,我都需要进入代码并修改 IP 地址。

Is there any way that the galileo board will automatically get the IP address of PC and adjust the IP address in the code.有什么办法可以让伽利略板自动获取PC的IP地址并在代码中调整IP地址。

You can solve this problem in one of two ways:您可以通过以下两种方式之一解决此问题:

  1. Assign a static IP address to the PC.为 PC 分配静态 IP 地址。 It's easy if both the board and the PC are behind the same NAT, or if your ISP can assign you a static IP address.如果主板和 PC 都在同一个 NAT 后面,或者如果您的 ISP 可以为您分配一个静态 IP 地址,这很容易。

  2. Use a dynamic DNS service such as no-ip or changeip .使用动态 DNS服务,例如no-ipchangeip You'll need to install an agent on the PC for that.为此,您需要在 PC 上安装代理。 The agent will update the service whenever the PC's address changes.只要 PC 的地址发生变化,代理就会更新服务。 The service will then make sure to answer DNS resolution request for <your subdomain>.dynmaic-dns.net with the PC's current IP address, so you'll be able program the board to always connect to <your subdomain>.dynmaic-dns.net然后,该服务将确保使用 PC 的当前 IP 地址回答<your subdomain>.dynmaic-dns.net DNS 解析请求,因此您可以对电路板进行编程以始终连接到<your subdomain>.dynmaic-dns.net

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

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