I'm trying to run a test using a local xmpp server in the browser.
import { client } from '#xmpp/client';
const xmpp = client({
service: 'xmpp://localhost:5222/',
username: 'user',
password: 'pass',
});
xmpp.start().catch(err => {
console.error('start failed', err);
});
But I get the following error:
No compatible connection method found.
From what I've read, the browser expects a websocket connection instead of an xmpp connection.
The xmpp.js documentation says that it supports websockets as well, but I'm not sure what I have to change in order to successfully connect. Do I have to add WS support to my XMPP server?
Most likely you would have to change your service URI - both protocol as well as port part. As per xmpp.js client documentation you should use:
service: 'ws://localhost:5280/xmpp-websocket',
Exact path may be xmpp-server dependent (i.e. xmpp-websocket may not be needed) - please check your server's documentation.
Related
I have created a server using net module:
// Creating and connecting with server
const net = require('net');
const server = net.createServer(); //Creating server
//Connecting with server
server.on('connection', function (socket) {
let remoteAddress = `${socket.remoteAddress},${socket.remotePort}`
console.log(remoteAddress)
console.log(`connection is established... ${Date.now()} \n `);
socket.write(`connection is established...${Date.now()} \n`);
//Receiving and Sending payload from/to client
socket.on('data', async function (payload) {
console.log("payload from client",payload)
socket.write(`acknowledge : ${payload}`);
});
//Close connection
socket.on('close', function () {
console.log('Server Connection Closed');
});
//Server error
socket.on('error', function (err) {
console.log("Caught flash policy server socket error: ")
console.log(err.stack)
});
});
server.listen(8001, function () {
console.log('Server Listing on Port 8001');
})
I deploy this code to AWS EC2 and When I tried to connect with telnet client (telnet ec2_ip 8001), initailly it is working but after sometime it is giving following errors.
screenshot of telnet client:
screenshot of ec2 logs:
And When I tried to connect with real IOT scooter with ec2 Ip address and port 8001, It is not connecting for even a second.
Can anyone please tell me what I am doing wrong?
Note: I don't have much knowledge about IoT. This is the first time I am connecting an IoT scooter with nodejs.
It is hard to know exactly what your problem is without seeing more of your code, or getting more explained. Like what happens in your real code? The logs seem to indicate that you are making outbound calls to another service after the initial connection. If that is the case, are you handling error conditions of your dependencies correctly? An unhandled exception would kill your server, and it would need to be restarted to work again. If you are using dependencies that fail, for instance databases, other servers, configuration files etc that fail on your scooter, that may be why it fails without even allowing one single connection. But without knowing more specifics about your application and architecture, it is just wild guesses at this point.
Your server example code, seems fine. As long as you have opened for traffic on that port in your routing configuration in AWS, it should respond. It could be that you just simply run out of connections, but again that requires me to know more to give you a definitive answer.
My advice would be to check your dependencies, and your logs for supporting systems.
recently I've been trying to create a WebSocket server (using the ws library for node.js). At first I used the ws unencrypted protocol, but then I had to switch to wss. This brought some client authentication issues. When the client (running on a browser)
(client.js)
this.socket = new WebSocket(`wss://ipv4.address:port`);
... tries to connect to the Node.js-based server
(server.mjs:)
const server = createServer({
cert: readFileSync('/path/to/ssl_certificate.cer'),
key: readFileSync('/path/to/private_key.key'),
ca: [
readFileSync('/etc/ssl/certs/ca-certificates.crt'),
readFileSync('/path/to/ssl_certificate_INTERMEDIATE.cer')
],
rejectUnauthorized: false
});
const wss = new WebSocketServer({ server });
server.listen(port, "hostname", () => {
//the server actually listens, so this line of code is printed
console.log(`listening on wss://${wss.address().address}:${server.address().port}`);
});
server.on("tlsClientError", (err, tlsSocket) => {
console.error("TLS client error", err);
tlsSocket.destroy();
});
... it goes into "tlsClientError", printing this:
TLS client error [Error: C0D71E8ECB7F0000:error:0A000416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown:../deps/openssl/openssl/ssl/record/rec_layer_s3.c:1584:SSL alert number 46
] {
library: 'SSL routines',
reason: 'sslv3 alert certificate unknown',
code: 'ERR_SSL_SSLV3_ALERT_CERTIFICATE_UNKNOWN'
}
This looks like the server isn't willing to accept the client's certificates. How do I set them? Is there something I'm not understanding about WebSockets over TLS?
I tried following the advice of many answers from StackOverflow, disabling rejectUnauthorized, but the node https server is still failing, even after adding the same SSL certificates my website is using (same hostname, different port)
EDIT:
I forgot to mention, that connecting from the same host as the server works (i.e. using the ws client part on the node side), as per https://github.com/websockets/ws/blob/master/examples/ssl.js, and even when disabling rejectUnauthorized (because I'm not using a self-signed certificate)
I have NodeJS Web App which trying to connect to the Azure Cache for Redis which is part of the same subscription.
const redis = require('redis')
const redisConnectionConfig = {
host: REDIS_HOST,
port: REDIS_PORT,
auth_pass: REDIS_PASSWORD
tls: { servername: REDIS_HOST }
}
...
redis.createClient(redisConnectionConfig)
I'm able to connect to Redis from my local machine after adding my IP to the Redis Firewall rules.
Also, I've added all 'Outbound IPs and Additional Outbound IP Addresses' from the Service App Properties.
I've tried even to allow access from all IPs
still not pass
But it is not connected and if I try to use Redis I receive the following connection error:
MaxRetriesPerRequestError: Reached the max retries per request limit (which is 20). Refer to "maxRetriesPerRequest" option for details.
Something similar solved for the VM here. But in the case of the App Service Azure managed that layer.
Looks like it's not connectivity issue.
Network part you always can check via WebApp->Console and use command
tccping redisservername:redisserverport
tcpping_example
Probably something with your redis cache size. What size are you using now?
You can find azure redis limits here
I'm developing an app that uses a FeathersJS server, and an Electron app that uses FeathersJS Socket.io client to connect to the server. I'd like to use channels in the Electron app to get notified when some data in the server has changed. The Electron app is an "autonomuos" app, so there isn't any user authentication or interaction. The Electron app will have a unique id that represents each machine it is running on.
Taking into account that there isn't any kind of authentication, how can I add the Electron app's unique id in the socket.io connection so that this id is received in the server and it can create the corresponding channel in the FeathersJS server?
Thank you!
How to pass information on the server from the Socket.io transport to Feathers through a Socket.io middleware is documented in the Socket.io transport API. There also is an example how to pass query parameters from the client to the server in the Socket.io documentation. Put together it looks like this on the client:
const socket = io('http://feathers-server.com', {
query: {
token: 'cde'
}
});
And like this on the server:
app.configure(socketio(function(io) {
io.use(function (socket, next) {
socket.feathers.token = socket.handshake.query.token;
next();
});
}));
socket.feathers is the exact same as the channel connection object so it will now have a token property you can use to join as a channel:
app.on('connection', connection => {
if (connection.token) {
app.channel(connection.token).join(connection);
}
});
I am trying to connect to a named Unix Domain Socket via nodejs. I have seen that the docs seem to support connecting to Unix Sockets, however I haven't seen any examples of connecting to a socket by name, and not by accessing a socket file at a well known location.
I can clearly see that the socket I need to connect to is being created by using lsof (and some grepping):
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
run 5632 user 3u unix 0xffff8803dd4b6000 0t0 29647 ##user#5632#1 type=SEQPACKET
The name of the socket is being passed to the script that actually runs my node script. I have tried the following:
import net = require('net');
var socket;
var element = "#user#5632#1"; //Parsed from args
try {
socket = net.createConnection("#"+element,(error)=>{
if(error){
console.log(error)
}else{
console.log("Connection Established "+element);}
});
socket.on('error', function(err) {
console.log("Error: " + err);
});
} catch (error) {
console.error(error);
}
Clearly, I have this wrapped up to catch errors in a few places(at different points in execution), but the point is that createConnection is throwing:
Error: Error: connect ENOENT ##user#5882#1
Using net.connectcauses the exact same error.
I tested creating a socket (file) in a well known location, and connecting to is, and that worked just fine, but as far as I have determined, node, or at least the net module does not seem to support connecting to ephemeral sockets.
Anybody know if there is a way to do this, or if I need to format my socket name differently in order to connect or any help really?
Node does not support SEQPACKET sockets. You may submit a PR to the node issue tracker as a feature request to add support and/or you may need to write a node addon that lets you connect to SEQPACKET sockets.