简体   繁体   English

如何仅使用局域网内的 IP 地址发送消息

[英]how to send messages using only IP address within LAN

I have two wifi modules that connects to my access point.我有两个 wifi 模块连接到我的接入点。 my android phone connects to the same access point.我的安卓手机连接到同一个接入点。 Is there a way in Java to be able to send a message to any of the clients from my phone using just the IP address. Java 中有没有一种方法可以仅使用 IP 地址从我的手机向任何客户端发送消息。 I do not want to run a server on my phone.我不想在手机上运行服务器。

I'll appreciate any assistance.我将不胜感激任何帮助。 Thanks谢谢

I feel there is a confusion about IP addresses and servers in general.我觉得一般来说 IP 地址和服务器存在混淆。 An IP address is a way to find an entity on the network (it is an address). IP 地址是一种在网络上查找实体的方法(它是一个地址)。 Since your phone is connected to the same access point, it is (very likely) on the same subnet.由于您的手机连接到同一个接入点,它(很可能)在同一个子网上。 What that means is that it can talk to any of the other entities without going through a gateway, that is all.这意味着它可以在不通过网关的情况下与任何其他实体交谈,仅此而已。

While it is able to talk to them, there has still to be some entity listening.虽然它能够与他们交谈,但仍然必须有一些实体在倾听。 When your phone sends a message to a particular address (the other node on the network), the packet may make it there, but for the communication to proceed:当您的手机向特定地址(网络上的另一个节点)发送消息时,数据包可能会到达那里,但要继续进行通信:

  • There has to be some listener on the other end that picks that incoming message另一端必须有一些侦听器来选择传入的消息
  • The communication has to follow a prescribed set of rules (protocol)通信必须遵循一组规定的规则(协议)

From what I gather, your phone is acting as the client, not the server.据我所知,您的手机充当客户端,而不是服务器。 It initiates communication with the other entity on the network.它启动与网络上其他实体的通信。 Depending on which node on the network you are trying to talk to, that node is supposed to be expecting that communication and know how to carry it forward.根据您尝试与网络上的哪个节点通信,该节点应该期待该通信并知道如何进行通信。

If you clarify the setup and your desire, may be you can get more to the point response.如果您澄清设置和您的愿望,也许您可​​以获得更切中要害的响应。

What you were not understanding here is that you can send the message to that device with ip address but that data will not be shown on that device's screen because you didn't provided any port number for a process which is listening on that particular device.您在这里不明白的是,您可以使用 ip 地址将消息发送到该设备,但该数据不会显示在该设备的屏幕上,因为您没有为正在该特定设备上侦听的进程提供任何端口号。 Your message will be sent but the device would not know what do with it.您的消息将被发送,但设备不知道如何处理它。

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

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