java - 我目前正在尝试创建一个可以将数据从浏览器发送到 android 应用程序的程序
问题描述
我目前正在尝试创建一个可以将数据从浏览器发送到 android 应用程序的程序,在这个程序中,我只能从浏览器到 Android Studio 虚拟机成功地做到这一点。但是我想将数据从浏览器发送到手机上的应用程序,我需要如何更改我的地址才能使其正常工作?
编辑:我是否必须使用相同的 wifi 才能使其工作?
//<code>im</code> in address is the endpoint configured in server.
//If you are using AVD provided by Android Studio, you should uncomment the upper address.
//If you are using Genymotion, nothing else to do.
public class Const {
public static final String TAG = "xlui";
public static final String placeholder = "placeholder";
private static final String ADDRESS = "ws://10.0.2.2:8080/im/websocket";//for android vm
//public static final String address = "ws://10.0.3.2:8080/im/websocket";//for Genymotion
public static final String broadcast = "/broadcast";
public static final String broadcastResponse = "/b";
// replace {@code placeholder} with group id
public static final String group = "/group/" + placeholder;
public static final String groupResponse = "/g/" + placeholder;
public static final String chat = "/chat";
// replace {@code placeholder} with user id
public static final String chatResponse = "/user/" + placeholder + "/msg";
}
解决方案
对于开发用途,我个人更喜欢本地解决方案。这意味着您使用与服务器相同的 WIFI 并使用该服务器的公共 IP 地址作为 IP。
例如,您的配置看起来像(在本地网络站点上)路由器运行在 10.0.0.1 服务器运行在 10.0.0.24 客户端运行在 10.0.0.50
所以网络套接字将运行"ws://10.0.0.24:8080/im/websocket"
推荐阅读
- c# - MVC:在 Ajax 调用上从控制器返回时,结果未定义
- java - 在 Docker php:7.1-apache-stretch 上安装 java
- java - 想通过 java API 将我的本地目录推送到 github
- c++ - 无法链接 libtiff
- grails - 获取 Grails 2.* 中其他环境的配置
- java - 使用 HttpUrlconnection 登录和上传图片的问题
- c# - Xamarin Forms 应用程序在恢复时生成并发运行的应用程序
- r - 在 R 中,选择列表中的子列表并实际保留子列表的名称,而不是顶部父名称
- java - elasticsearch 6.3.2 的 NestedSortBuilder 使用示例
- go - 在 Go 中使用递归练习“裸返回”。我的 ELSE 语句中的 return 语句是否不正确?