Having problems running WebSocket for mqtt - javascript

I'm trying to replicate this demo
using my own mosquitto instance to control the meter. When I try to connect to "test.mosquitto.org", 8080 everything works great, but when I plug my own mqtt server's IP I receive: Connection failed: AMQJ0007E Socket error:undefined.
I believe this is due to the requirement of a websocket service to run on the same machine as the mqtt. The original author uses WSS, and I can't figure out how to install this service (complete noob). I Even tried to follow these directions with no luck Could anyone give some directions?

You can try Installing him HiveMQ while you wait for mosquito 1.4. That is a broker with websockets built in.

The easiest answer to this is probably to wait for Mosquitto v1.4 to ship which has baked in Websocket support.
If you can't wait for it to ship you can build from the development head stream which will get you what your looking for. You've not said what platform you are running the broker on, but these instructions should help on Linux: http://goochgooch.wordpress.com/2014/08/01/building-mosquitto-1-4/

Mosquitto v1.4 has been released on February 18th, 2015. It has inbuilt support for websockets.

Related

import WebSocket from 'ws' in browser

I am a Korean developer.
I'm making a game and a game bot now.
Games run on WebGL and gamebots run on node JS.
There is a game git in the gamebot git. Because the game bot git has only scenario and is basically the same as normal game
The problem is, I'm using WebSocket in the code in this game git, but I imported the ws library because Node Js does not support WebSocket.
But,
import WebSocket from 'ws';
This code causes an error in the browser.
What should I do to use the websocket in both Nodejs and Browser with the same code?
You can't use a websocket on the back and the frond end with the same code if only because they do different things. In the browser you don't need to import anything as websockets are supported natively. You can read on it in MDN: https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_client_applications

pusher without internet connection

I'm using laravel 5.4 with pusher to build a real-time application , but I have poor internet connection so I'm wondering if I can use a pusher bridge instead and if it doesn't need an internet connection ?
You need to configure another driver for Laravel because Pusher is a third-party service (needs internet), that manages all the web socket server. I also found out this behavior of Pusher and for that, I searched for another driver. Redis is the second option. Choosing Redis requires a Websocket server to be configured in order to manage all the connection (Pusher's tasks). This is because Redis only handles the sending of messages to the channels but doesn't do everything that Pusher does.
Install Predis on your Laravel project using this command composer require predis/predis.
Install Redis on your local server.
Then install this: https://github.com/tlaverdure/laravel-echo-server in order to install a socket.io server implementation compatible with Laravel. (Socket.io will be responsible now for managing the connections into the channels defined in Laravel).
Pusher requires an Internet connection to work unfortunately - however you should know that Pusher can deal with sketchy Internet connections fairly well, so you maybe could give it a try and see how well it works!

Cannot connect to mosquitto broker from local web client on windows

I am trying to connect to mosquitto windows broker service on my machine through javascript. I understand that Paho javascript client connects only through websockets and mosquitto for windows doesn't support websockets unless you build it yourself. My question is that since I am trying to connect to localhost should it matter to have a websockets enabled mqtt broker? Is there any way to connect to a local mqtt server without using websockets through javascript? And is it unsafe to do so or is it fine since I am connecting to a local server itself?
Thanks in advance for the answer and sorry if it sounds lame to you. I am extremely new to this space.
Even when connecting to localhost you still need websockets support to use the paho JavaScript support.
There are some small apps that will set up a separate websocket listener and bridge that to pure native MQTT e.g.
http://hai-ng.blogspot.co.uk/2014/08/setting-up-mqtt-websocket-gateway-with.html

Kurento Media Server HelloWorld Javascript example webSocket error

Merry Christmas!
I am trying to configure KMS on my Ubuntu 14.04 (64 bit). I could install the KMS server successfully following the guide at https://www.kurento.org/docs/6.0.0/installation_guide.html.
Also, downloaded the Javascript HelloWorld tutorial from https://www.kurento.org/docs/6.0.0/tutorials/js/tutorial-1-helloworld.html. I could run the example successfully on localhost on Google Chrome Version 47.0.2526.106 (64-bit) on the same Ubuntu System.
But, I could not see the local video nor the loop backed video. Only a spinner icon is shown on both the Video placeholders. Consulting the Console log reveals a problem after creating the SDP offer. The error is as described below.
kurento-client.js:21072 WebSocket connection to 'wss://127.0.0.1:8433/kurento' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
I am no expert on web sockets and stuff. Any help on this would really help me to proceed forward.
Note: I am running the example on HTTP, not on HTTPS. I guess that would not be the cause of the problem, though.
Regards,
LazyCoder7
I managed to solve it. I was wrong on my guess though, HTTPS was indeed required in order to make the WebSocket connection ( i was not aware of that part ). Created a certificate file (.pem) (from crt and key file already in the helloworld folder) and configured the KMS server to use the certificate. After this I was able to see myself and the same me in loopback :)
You are following an old version of the documentation. Since Chrome 47, in is mandatory to server pages through HTTPS if you want to use the getUserMedia APi. So we updated all our tutorials, and they now have a self-signed certificate. In case of the JS tutorials, you also need to configure KMS to expose a secure WS signalling connection, as the browser directly connects to the media server to control it.
Please follow the latest version of the documentation here
Be sure that the KMS is running on the port 8433 (not 8888), if you are using docker
docker run -d --name kms -p 8433:8433 kurento/kurento-media-server:trusty-latest

Installing/setting up Socket.IO on my server

Ok so I have read through the Socket.IO docs and I am still a little unsure of a couple of points:
The documentation says...
To run the demo, execute the following:
git clone git://github.com/LearnBoost/Socket.IO-node.git socket.io
cd socket.io/example/
sudo node server.js
Now I don't know what this means at all! I think it may be command line interface. I of course have access to this on my localhost, but my online hosting package is a shared LAMP setup. Meaning I don't have access to the root command line (i think).
How do I actually setup socket.IO, is it impossible on my shared server package?
Appreciate any help...
W.
If you aren't familiar with node.js or with basic command line usage then I would suggest that you use a hosted WebSockets solution like pusherapp. Trying to learn WebSockets, and Node.js, and the Linux command line all at once is going to lead to a lot of frustration. Take a look a pusherapp's quick start guide, it's very easy to get started. You can have 5 simultaneous connections with a single application for free (I'm not affiliated with pusherapp).
Updated (with inline answers to questions):
If you are going to go the direction of running a Socket.IO application:
You don't technically need git since you can download node.js and Socket.IO from their respective download links on github.
You don't actually need a LAMP server to use Socket.IO. By default Socket.IO functions as a simple webserver in addition to a WebSockets server. If you want server side scripting then you might want Apache with mod_php, mod_python, etc.
You don't technically need a dedicated server or even root access. You do need a system where you can have long running process. And if you want the service to start automatically when the system is rebooted, you probably want to add a startup file to /etc/init.d, /etc/rc.d which will require root access. Both node.js and Socket.IO can be installed and run from a normal home directory. If you want to run Socket.IO on a standard port like 80 or 443 then you will need to run it with root privilege.
Node.JS scales quite well so Socket.IO will probably scale pretty well too.
It's not a simple matter to get everything setup and working, but if your goal is a free solution for web serving+WebSockets then Socket.IO is probably is good route to at least explore if you are brave.
First you'll have to determine if your host supports SSH. Sometimes they don't by default on shared hosting, but if you ask they can turn it on. If it does you'll use some sort of SSH client to connect to it. Putty for windows is the most common. Then you'll use git, which is a source control program. Which you'll probably have to install on your host, which may or may not be allowed. If you can, this can be accomplished a number of ways, you'll want to read the git documentation, it will depend largely on what linux distribution you're running. CD is change directory, basic command line stuff. sudo on the last line is telling the system to run the command as root, which it will ask you the password for, which you may not have access to on your host. Sounds like you're gonna have an uphill battle on shared hosting. You may want to opt for a VPS instead.
If your shared host is a LAMP system with no command line access you're not going to get very far with Socket.IO. The instructions you posted assume you have command line access and that you've installed the node.js runtime on your system.
If you really want to try this I recommend you get a VPS of your own (I use prgmr.com) to test it out. For what it's worth I found the Socket.IO platform pretty nice to use once I got it up and running.

Categories