Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working on Android #15

Open
prameetchakraborty opened this issue Dec 5, 2017 · 9 comments
Open

Not working on Android #15

prameetchakraborty opened this issue Dec 5, 2017 · 9 comments

Comments

@prameetchakraborty
Copy link

prameetchakraborty commented Dec 5, 2017

The package works perfectly on iOS. However, when I run on Android, with the exact same parameters and code, I get this (AMQJS0007E Socket error:undefined). Any solutions?

@nicolascouvrat
Copy link

Hello,

If you try to run directly with the example code, there seems to be a mistake in it (I'm running on Android).
A quick look at Paho's source code shows that a call to new Paho.MQTT.Client() has different behaviors depending on the numbers of arguments you give it.

  • 2 arguments : first one has to be the full path, second one is client id,
  • 3 arguments : the first one has to be the host name (ws:// is automatically appended), second is port, third is client id, but for some reason that I do not know, /mqtt gets automatically appended as a relative path.
  • 4 arguments : first is hostname, second is port, third is path, fourth is client id.

Tl;dr: These are are valid ways to connect but @Introvertuous 's example is flawed

// the two open brokers provided by eclispe are:
//    ws://iot.eclipse.org:80/ws (non SSL)
//    ws://iot.eclipse.org:443/ws (SSL)

// this will resolve to ws://iot.eclipse.org:443/ws => ok
const client = new Paho.MQTT.Client(
  'ws://iot.eclipse.org:443/ws',
  'clientId'
);

// this will resolve to ws://iot.eclipse.org:443/mqtt => does not exist!
const client = new Paho.MQTT.Client(
  'iot.eclipse.org',
  443,
  'clientId'
);

// this will resolve to ws://iot.eclipse.org:443/ws => ok
const client = new Paho.MQTT.Client(
  'iot.eclipse.org',
  443,
  '/ws',
  'clientId'
);

That might solve your issue?

@Introvertuous
Copy link
Owner

@nicolascouvrat is correct, but for some reason, the example I created did work properly (messages were received on the other end of the socket). I will fix that when I get a chance but I have a feeling this error is being caused by something else.

@SilajitBukaiSil
Copy link

How to set with server ip address instead or using 'iot.eclipse.org', and '443'. Means I want to say can we use Ip address like: '192.21.23.210' and port number '1883'. If anybody know, please reply. I already try, but in android is not working!!

@nelsonec87
Copy link

My app works fine in debug, but when I generate the release apk I get AMQJS0007E (same device, same network). Any ideas?

@chentianci123
Copy link

我的应用程序在调试中运行良好,但是当我生成发行版APK时,我得到了AMQJS0007E(同一设备,相同网络)。有任何想法吗?

我也遇到相同问题了,您的问题解决了吗

@chentianci123
Copy link

如何设置服务器IP地址或使用“ iot.eclipse.org”和“ 443”。就是说我想说我们可以使用Ip地址,例如:“ 192.21.23.210”和端口号“ 1883”。如果有人知道,请回复。我已经尝试过了,但是在android中不起作用!

请问您的问题解决了吗,我和您遇到了相同的问题

@chentianci123
Copy link

你好,

如果您尝试直接使用示例代码运行,则似乎有误(我在Android上运行)。
快速浏览Paho的源代码可知,new Paho.MQTT.Client()根据您提供的参数数量,对的调用具有不同的行为。

  • 2个参数:第一个必须是完整路径,第二个是客户端ID,
  • 3个参数:第一个必须是主机名(ws://自动添加),第二个是端口,第三个是客户端ID,但是由于某种原因(我不知道),/mqtt会自动添加为相对路径
  • 4个参数:第一个是主机名,第二个是端口,第三个是路径,第四个是客户端ID。

Tl; dr:这些是有效的连接方式,但是@Introvertuous的示例存在缺陷

// eclispe提供的两个开放代理是:
//     ws://iot.eclipse.org:80 / ws(非SSL)
//     ws://iot.eclipse.org:443 / ws(SSL)

//这将解析为ws://iot.eclipse.org:443 / ws =>好的
const  client  =  new  Paho.MQTT.Client(
   ' ws://iot.eclipse.org:443 / ws '
   ' clientId '
;

//这将解析为ws://iot.eclipse.org:443 / mqtt =>不存在!
const  client  =  new  Paho.MQTT.Client(
   ' iot.eclipse.org '
   443
   ' clientId '
;

//这将解析为ws://iot.eclipse.org:443 / ws =>好的
const  client  =  new  Paho.MQTT.Client(
   ' iot.eclipse.org '
   443
   ' / ws '
   ' clientId ' 
;

那可以解决您的问题吗?

我是用您的事例还是连接失败,请问有什么好的解决方法吗

@xdlgj
Copy link

xdlgj commented Mar 30, 2020

如何设置服务器IP地址或使用“ iot.eclipse.org”和“ 443”。就是说我想说我们可以使用Ip地址,例如:“ 192.21.23.210”和端口号“ 1883”。如果有人知道,请回复。我已经尝试过了,但是在android中不起作用!

请问您的问题解决了吗,我和您遇到了相同的问题

@chentianci123 , 你好,你的问题解决了吗?我现在遇到了同样的问题,我查看资料好像是说这个插件只支持websocket,不支持TCP

@inkCrazy
Copy link

inkCrazy commented Mar 5, 2021

如何设置服务器IP地址或使用“ iot.eclipse.org”和“ 443”。就是说我想说我们可以使用Ip地址,例如:“ 192.21.23.210”和端口号“ 1883”。如果有人知道,请回复。我已经尝试过了,但是在android中不起作用!

请问您的问题解决了吗,我和您遇到了相同的问题

@chentianci123 , 你好,你的问题解决了吗?我现在遇到了同样的问题,我查看资料好像是说这个插件只支持websocket,不支持TCP

你问题解决了吗,我的react native 0.57.8 react-native-mqtt1.3.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants