【问题标题】:I am currently trying to create an program that can send data from browser to android app [closed]我目前正在尝试创建一个可以将数据从浏览器发送到 android 应用程序的程序 [关闭]
【发布时间】:2021-11-19 10:37:32
【问题描述】:

我目前正在尝试创建一个可以将数据从浏览器发送到 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";
}

【问题讨论】:

    标签: java websocket okhttp stomp


    【解决方案1】:

    对于开发用途,我个人更喜欢本地解决方案。这意味着您使用与服务器相同的WIFI,并使用该服务器的公共IP地址作为IP。

    例如,您的配置看起来像这样(在本地网络站点上) 路由器在 10.0.0.1 上运行 服务器在 10.0.0.24 上运行 客户端在 10.0.0.50 上运行

    所以网络套接字将在 "ws://10.0.0.24:8080/im/websocket" 上运行

    【讨论】:

      猜你喜欢
      • 2016-07-30
      • 1970-01-01
      • 2012-10-12
      • 1970-01-01
      • 2014-11-01
      • 1970-01-01
      • 2020-03-16
      • 2016-05-21
      • 1970-01-01
      相关资源
      最近更新 更多