I need to make a websocket connection to a wss address (a secure websocket connection). When I run the program I get Connect Error: Error: unable to verify the first certificate. Is there some way to set ssl certificates for the client so that I do not see this error?
Code:
var WebSocketClient = require('websocket').client;
var client = new WebSocketClient();
client.on('connectFailed', function (error)
{
console.log('Connect Error: ' + error.toString());
});
client.on('connect', function (connection)
{
console.log('WebSocket Client Connected');
connection.on('error', function (error)
{
console.log("Connection Error2: " + error.toString());
});
});
client.connect('wss://dev-api.dev2.test.com:4900/ws/v1/4/Data/Value', 'echo-protocol');
Related
I'm attempting to connect to an Active Directory domain controller to make some basic LDAP queries using JavaScript. I'm using the LDAPJS library and the built-in node tls module. I'm getting an error when attempting to run client.bind
The TLS connection seems to be working fine (it's coming back as authorized===true, though on the secureConnect event, I'm getting undefined.
The related code and output is below:
var tlsOptions = {
host: "my.domain.controller.net",
port: portNumber,
ca: fs.readFileSync("C:\\myCA.pem"),
};
var server = tls.connect(tlsOptions, function () {
console.log(
"Server connected",
server.authorized ? "and authorized" : "but UNAUTHORIZED"
);
if (server.authorized) {
var client = ldap.createClient({
url: "ldaps://domiancontroler",
tlsOptions: tlsOptions,
});
console.log("Client created!")
client.bind(userDN, userPW, function (err) {
console.log("Client binding error:", err)
process.exit()
});
}
});
server.setEncoding("utf8");
server.on("data", function (data) {
console.log("server data callback: ", data);
});
server.on("secureConnect", function (data) {
console.log("server secureConnect callback: ", data);
});
server.on("error", function (error) {
console.log("server error callback", error);
});
Produces the following output:
> Server connected and authorized
> Client created!
> server secureConnect callback: undefined
> Client binding error: null
I have a two webservers both running https with the same certificates, I have a main shard that the user connects to example.com, they retrieve some data and try to connect to an ip address on the 2nd shard via websocket.
But no matter what I configure I get an Error 1006 on the client side when connecting to the 2nd shard. Firefox devtooling gives me multiple errors - ssl_error_bad_cert_domain, SSL_ERROR_RX_RECORD_TOO_LONG.
The certificates are issued and signed, I was wondering where I should go from here. Thanks :)
SHARD2
const options = {
key: './server.key',
cert: './server.cert'
};
var https = require('https').Server(options);
https.listen(443, function () {
// console.log('Https listening on *: 443');
});
let WebSocket = require('ws');
let socket = new WebSocket.Server({ server:https });
socket.on('connection', function (ws, req) {
ws.on('message', (msgRaw) =>{
});
ws.on('close', function(code, reason) {
});
ws.on('error', function(error) {
console.log(error);
ws.close();
});
});
CLIENT
function connect() {
"use strict";
window.WebSocket = window.WebSocket || window.MozWebSocket;
if (!window.WebSocket) {
alert('Your browser doesn\'t support WebSocket');
return;
}
wss = new WebSocket('wss://123.123.123.120/:443');
wss.onmessage = function(event) {
};
wss.onerror = function(event) {
console.log(`wss error: ${JSON.stringify(event)}`);
};
wss.onclose = function(event) {
};
}
Useful sys diagram?
I am very new to mqtt and recently is tasked to establish a connection using mqtt broker. I have this mqtt settings all set up, but unable to connect. I get this error every time the connect() function is called Connection failed: AMQJSC0001E Connect timed out. I'm running this over Xampp.
<html>
<head>
<script>
var options = {
timeout: 3,
userName: "myusername",
password: "mypassword",
onSuccess: function () {
alert("Connected");
console.log("mqtt connected");
//Connection succeeded; subscribe to our topic
client.subscribe(MQTTsubTopic, {qos: 0});
},
onFailure: function (message) {
alert("Connection failed: " + message.errorMessage);
console.log("connection failed");
}
};
//Create MQTT client here
var client = new Paho.MQTT.Client(MQTTbroker, MQTTport, "myclientid_" + parseInt(Math.random() * 100, 10));
client.onConnectionLost = function (responseObject) {
alert("connection lost: " + responseObject.errorMessage);
console.log("connection lost");
/* Connect to MQTT broker */
client.connect(options);
};
</script>
</head>
</html>
Here's my MQTT broker and port information which i have defined in another js file. '000.000.00.00' isn't a real broker. What could possibly be wrong in my connection establishment?
var MQTTbroker = '000.000.00.00';
var MQTTport = 9001;
On the other hand I attempted to connect with a sample broker broker.emqx.io with port 8083 and it's connected. I got the example from this link
I have created one socket server in node js where I can send some data and receive from the server, but the problem is every time connection is closing and creating new PID for another request. here my requirement is once my IOT device connects to the server then the connection should stay there and I want to send, receive data any time.
Can anyone help me out?
I am posting my code below
Server code
var net = require('net');
// Create Server instance
var server = net.createServer(main);
server.listen(9010, function() {
console.log('server listening on %j', server.address());
});
function main(sock) {
sock.setEncoding("utf8");
sock.on('data', function(data) {
var data = data;
console.log('Request data is ', data);
console.log('Says:', data);
sock.write("responding to client");
sock.write(' exit');
});
sock.on('close', function () {
console.log('connection closed');
});
sock.on('error', function (err) {
console.log('Connection error: %s', err.message);
});
};
Client code
var net = require('net');
//params
var HOST = 'myhost';
var PORT = 9010;
var client = new net.Socket();
client.connect(PORT, HOST, function() {
console.log('CONNECTED TO: ' + HOST + ':' + PORT);
client.write('Hello socket server');
});
client.on('data', function(data) {
console.log('Recieved data: ' + data);
client.destroy();
});
// Add a 'close' event handler for the client socket
client.on('close', function() {
console.log('Connection closed');
});
I am building a desktop audio streaming application, which will be a client, i wish to connect to a server socket to stream audio, i have the host ip, the port and password. I am using node to connect:
var client = net.connect(serverDetails, function() { //'connect' listener
console.log('client created!');
});
client.on('connect', function() {
console.log('connected to: '+serverDetails.host+' port: '+serverDetails.port );
//client.write(serverDetails.password+'\r\n');
});
client.on('data', function(data) {
console.log('sending data to server!');
console.log(data.toString());
});
client.on('end', function() {
console.log('disconnected from server');
client.end();
});
at the moment it connects and the disconnects straight away, how can i pass the password so that the connection remains open? after which i can stream/send data to this socket.