I've downloaded a sample socket project from github https://github.com/appcoda/SocketIOChat
I'm using EICapitan and I've installed node js and I've also setup the IP in the sample var socket: SocketIOClient = SocketIOClient(socketURL: NSURL(string: "http://192.168.1.2:3000")!)
When I run node index.js command on terminal it shows Listening on *:3000 But when I run the sample app enter a name to connect user I dont receive any message like user connected. Is there something that I'm missing, I'm a beginner to node.js and socket.io. Any help is appreciated.
Seems like you are trying connect to incorrect ip address.
Get your inet ip from ifconfig and place it to SocketIOClient. I would recommend you to use localhost or 127.0.0.1 for development instead of inet address
Related
In Python Flask, I tried creating an ad hoc and OpenSSL based certificate as shared in https://blog.miguelgrinberg.com/post/running-your-flask-application-over-https
I also tried the approach where we create root CA, trust it and create certificates as shared in https://github.com/dakshshah96/local-cert-generator/issues/13 with Python Flask and Express JS
But I am unable to talk to https://192.168.0.5:5000 hosted on my Mac, from a different device without manually approving the site on every load. Ultimately, I wish to talk to this server over a web socket, which fails as the site requires manual approval. Any other ideas on how to make this multi-system setup work?
The example which I am going to deliver will run your application in the local network and it will be accessible using your computer (server) IP address over HTTPS.
You need to install OpenSSL to generate a self-signed certificate.
Create a project folder.
Open CMD and navigate to your project folder.
Run the following command on CMD
openssl req -nodes -new -x509 -keyout server.key -out server.cert
It will ask you some questions, answer them.
In your project folder, create app.js file and insert the following code:
let express = require('express')
let fs = require('fs')
let https = require('https')
let app = express()
app.get('/', function (req, res) {
res.send('hello world')
})
https.createServer({
key: fs.readFileSync('server.key'),
cert: fs.readFileSync('server.cert')
}, app)
.listen(3000, function () {
console.log('Example app listening on port 3000! Go to https://localhost:3000/')
})
Find your local IP address using ipconfig command. Your IP address will appear something like
IPv4 Address. . . . . . . . . . . : 192.168.1.124
Run your NodeJs server by using the command:
node app.js
You will get the following message:
Example app listening on port 3000! Go to https://localhost:3000/
Go to the browser and visit https://your_ip:3000/;
You will get a warning, ignore it. This is to alert that the certificate which you are using is a self-signed certificate and not issued by CA.
You can use the link to visit your application from any other device on your network. If you are tired of port 3000, you can use port 443 which is the default port for HTTPS. In that case, your URL will be simplified to something like https://your_ip/
I have verified through Wireshark that data is encrypted now!!
To answer this question, I took help from https://flaviocopes.com/express-https-self-signed-certificate/
I am trying to connect to my MS SQL database via node.js (Express), but the connection cannot be established. I have probably wrong configuration, but I have tried everything and nothing worked. I also enabled TCP/IP in configuration Manager.
Here is my JS code: https://snipboard.io/ufk49d.jpg
Here is one of my errors: https://snipboard.io/wyTbLi.jpg
When I add localhost or IP adress before SQLEXPRESS in server configuration, it thow this error: https://snipboard.io/RE6Xov.jpg
And also, I added new user and allow SQL auth and windows auth connection.
Thanks for your tips!
Can you put your machine name in server parameter?
server: 'YOUR_MACHINE_NAME\\SQLEXPRESS',
I've been given a project that is using a Paho/MQTT client through Javascript to update a web page. The project starts an http server through python on localhost:8080 and then, when the webpage is loaded, a main.js script starts the client and runs the connect as shown below:
var client = new Paho.MQTT.Client("localhost",Number(8080),'0');
client.onConnectionLost = onConLost;
client.onMessageArrived = onMesArvd;
console.log("start connection...");
client.connect({onSuccess: onConnect});
The problem is that upon trying to connect the below error appears and the onConnect method does not appear to connect as a console.log does not appear:
WebSocket connection to 'ws://localhost:8080/mqtt' failed: Error during WebSocket handshake: Unexpected response code: 404
The code highlighted in red in the paho-mqtt.js is below:
new WebSocket(a, ["mqtt"])
I tried adding a mqtt file to the folder localhost is being run from but it only changes the response code (301 if a mqtt folder is present, 200 if a file).
Adding the mosquitto.conf that came with the project:
pid_file /var/run/mosquitto.pid
persistence true
persistence_location /var/lib/mosquitto/
log_dest file /var/log/mosquitto/mosquitto.log
include_dir /etc/mosquitto/conf.d
listener 1883
listener 8080
protocol websockets
I noticed it's not in the same folder as the paho/mqtt client but in ../dir2/setup/.
I've looked around but I haven't seen anyone with this issue so any help/guidance would be greatly appreciated. Thanks!
Thanks to Santosh Balaji for pointing me in the right direction on this one.
I believe I needed to install mosquitto on the pi and then change the mosquitto.conf file in the mosquitto install dir to the one provided by the project. After installing and confirming my conf was being used the js and Python connected without issue.
1) Is port 8080 occupied by other process before starting mqtt. Try to start your mosquitto with conf file. It will show up error if there is anything wrong with the start.
mosquitto -c mosquitto.conf
2) Try changing the port to 9001 as it is default port for using websockets in mqtt
So I've deployed my meteor app, and have it up and running on an instance.
I've used the following environment variables:
MONGO_URL='mongodb://localhost:27017/meteor'
ROOT_URL='http://<my static ip>'
PORT=3000
And I run the program using the following command:
node bundle/main.js
It prints my "Meteor is starting up" that is printed using the console.log command, and then doesn't error out, but when I navigate to http://< my static ip >:3000 in a browser, I get an ERR_CONNECTION_REFUSED result.
My open mongod terminal says it's connecting fine to the MongoDB database.
Does anyone have any ideas on how to start debugging this issue?
Thanks.
In server you don't need to run meteor application on port 3000. You can run it on port 80 if the port is not being used by any other program.
If you are using port 80 make sure port 80 is opened by the network security rules.
If you are using port 3000 or any other port you will have to make sure that port is opened by the network security rules as above. Additionally you will have to mention the IP in your url, like http://<your_ip>:<port>
I am trying to access Mongodb in the virtualbox hosted Ubuntu. When I am developing app in Ubuntu, I used "meteor create {app_name}"
I didnt change the default Mongodb. So when I am running Meteor app using "meteor" command, I cant access the mongodb.
In my Robomongo app in Windows, I am using this credentials,
"192.168.1.13:3001" as host and port. But It says "failed to connect".
What Do i need to do to connect to my mongodb?
Hey After doing some digging I find out the solution.
steps you need to follow:
Go to the following path cd /etc
There you will find a file called mongod.conf open this file with the help of
sudo vim mongod.conf
3.You will be in a file type i and find bindIp written over there.
4.now you need to change your bindIp of mongodb to 0.0.0.0
5.type ctrl +c then :wq // write and quite
6.sudo service mongod restart
7.Go to your robomongo and create connection and in address field just type your ip (192.168.1.13) // no port number is required in which you are running the code port will be default port on which mongodb runs 27017
I have found that using no bind ip in mongod.conf and adding localhost 127.0.0.1 to the hosts.conf works