So i recently switch to having SSL through cloudflare and have it set to flexible and I haven't been able to connect to my socket i was getting a Access-Control-Allow-Origin error but then i added
var connectionOptions = {
"force new connection" : true,
"reconnectionAttempts": "Infinity", //avoid having user reconnect manually in order to prevent dead clients after a server restart
"timeout" : 10000, //before connect_error and connect_timeout are emitted.
"transports" : ["websocket"],
"secure" : true
};
SOCKET = io('wss://my_site:8443', connectionOptions);
and that got rid of the Allow Origin error but now im getting
WebSocket connection to 'wss://my_site:8443/socket.io/?EIO=3&transport=websocket' failed: Error during WebSocket handshake: Unexpected response code: 525
My backend code:
var io = require('socket.io')(8443);
io.set('transports', [ 'websocket' ]);
io.on('connection', function(socket){
//...
});
Related
I am trying to make an https request in my backend node.js web app. I have the following code:
const express = require('express');
const https = require('https');
const app = express();
app.get("/", function(req, res) {
const url = "https://www.tkmaxx.com/uk/en/women/edits/big-brand-drop/c/01240000/autoLoad?page=1"
https.get(url, function(response) {
console.log(response.statusCode);
});
res.send("running test")
});
app.listen(3000, function() {
console.log("Server started on port 3000");
});
I am getting the following error:
node:events:504
throw er; // Unhandled 'error' event
^
Error: socket hang up
at connResetException (node:internal/errors:691:14)
at TLSSocket.socketOnEnd (node:_http_client:466:23)
at TLSSocket.emit (node:events:538:35)
at endReadableNT (node:internal/streams/readable:1345:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
Emitted 'error' event on ClientRequest instance at:
at TLSSocket.socketOnEnd (node:_http_client:466:9)
at TLSSocket.emit (node:events:538:35)
at endReadableNT (node:internal/streams/readable:1345:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21) { code: 'ECONNRESET' }
Anyone know what's going on? Is the issues related to request headers or user agent? How can I set that?
The request is only accepted by the remote server if it has an Accept header and also Connection: keep-alive. (These are headers a browser typically sets.)
https.get("https://www.tkmaxx.com/uk/en/women/edits/big-brand-drop/c/01240000/autoLoad?page=1", {
headers: {
accept: "text/html",
connection: "keep-alive"
}
}, function(response) {...});
(Perhaps this is a mechanism which the remote server employs to guard against requests made by clients other than browsers?)
A few months ago I created this script to help me send multiple mails at once instead of sending them one by one, and it was working perfectly till now.
For this script, I've used dotenv, nodemailer, and nodemon (only in development, when I finished it I started using npm run start to run it)
(function main() {
const { contacts } = contacts_list;
try {
const { MAIL_ACCOUNT, MAIL_PASSWORD } = process.env;
const transport = nodemailer.createTransport({
// Uses 'pool' attribute: The same connection is used to send up to 100 mails before being disposed.
pool: true,
// Sets the number of max connections per transport. Microsoft accepts up to 1 parallel connection for the same client.
maxConnections: 1,
logger: true,
debug: true,
service: "hotmail",
auth: {
user: MAIL_ACCOUNT,
pass: MAIL_PASSWORD
},
tls: { rejectUnauthorized: false }
})
// Change mail parameters such as subject, recipients, content, etc
const mailParams = {
from: `test <${MAIL_ACCOUNT}>`,
to: '',
attachments: [],
subject: `test`,
text: `test`,
html: `<h1>test</h1>`
}
// Mail every contact once at a time with its corresponding attachments
contacts.forEach(async (contact) => {
mailParams.to = contact.email;
mailParams.attachments = [...contact.attachments];
await transport.sendMail(mailParams);
})
} catch (err) {
console.error(err);
}
})();
I've already scanned for blocked ports, disabled firewall when trying to use it and antivirus as well. None of these approaches worked.
It throws the following error:
node:internal/process/promises:246
triggerUncaughtException(err, true /* fromPromise */);
^
Error: connect ETIMEDOUT xxx.xx.xxx.xxx:587
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16) {
errno: -4039,
code: 'ESOCKET',
syscall: 'connect',
address: 'xxx.xx.xxx.xxx',
port: 587,
command: 'CONN'
}
Logger prints the following lines:
[2022-02-03 01:39:22] DEBUG Creating transport: nodemailer (6.7.2; +https://nodemailer.com/; SMTP (pool)/6.7.2[client:6.7.2])
[2022-02-03 01:39:22] DEBUG Sending mail using SMTP (pool)/6.7.2[client:6.7.2]
[2022-02-03 01:39:22] DEBUG Sending mail using SMTP (pool)/6.7.2[client:6.7.2]
[2022-02-03 01:39:22] INFO [#1] Created new pool resource #1
[2022-02-03 01:39:22] DEBUG [#1] Assigned message <567cc726-524b-0bda-5a52-698109ae7d78#hotmail.com> to #1 (1)
[2022-02-03 01:39:22] DEBUG [nHXJGQWMbA] Resolved smtp.live.com as xxx.xx.xxx.xxx [cache miss]
[2022-02-03 01:39:43] ERROR [nHXJGQWMbA] connect ETIMEDOUT xxx.xx.xxx.xxx:587
[2022-02-03 01:39:43] ERROR [#1] Pool Error for #1: connect ETIMEDOUT xxx.xx.xxx.xxx:587
[2022-02-03 01:39:43] ERROR Send Error: connect ETIMEDOUT xxx.xx.xxx.xxx:587
[2022-02-03 01:39:43] DEBUG [nHXJGQWMbA] Closing connection to the server using "destroy"
[2022-02-03 01:39:43] INFO [#1] Connection #1 was closed
If you know how to solve it, i'll be very grateful if you lend me a hand!
SOLUTION:
Finally, I found the solution thanks to #Marco Strahilov 's answer in other post. When instantiating the transport, set the service property to 'smtp-mail.outlook.com' instead of hotmail. I don't know for sure why 'hotmail' stopped working nor why 'stmp-email.outlook.com' works now.
go to
Settings => View All Outlook settings => Mail => Sync email
here is info for your correct settings IMAP, POP, SMTP
Finally, I found the solution thanks to #Marco Strahilov 's answer in other post.
When instantiating the transport, set the service property to 'smtp-mail.outlook.com' instead of hotmail. I don't know for sure why 'hotmail' stopped working.
i've searched through several tutorials and questions on stackoverflow and other sites but i can't still figure out why my script is producing an Error: socket hang up...
Hope you guys can help me
I'v implemented a https server like in the tutorial on https://www.pixelstech.net/article/1445603357-A-HTTPS-client-and-HTTPS-server-demo-in-Java
works perfectly and also the client works.
But when i want to create a request in javascript and run it with node js i'm getting the known error...
My .js file:
var https = require('https');
var data = JSON.stringify({
firstName: 'JoaquÌn',
});
function getCall() {
//initialize options values, the value of the method can be changed to POST to make https post calls
var options = {
host : 'localhost',
port : 9999,
path : '/',
rejectUnauthorized: false,
method : 'POST',
headers: {'Connection': 'keep-alive',
'Content-Type': 'application/json; charset=utf-8',
'Content-Length': Buffer.byteLength(data)}
}
//making the https get call
var getReq = https.request(options, function(res) {
console.log("\nstatus code: ", res.statusCode);
res.on('data', function(data) {
console.log( JSON.parse(data) );
});
});
//end the request
getReq.end();
getReq.on('error', function(err){
console.log("Error: ", err);
});
}
getCall();
My Error:
Error: { Error: socket hang up
at createHangUpError (_http_client.js:253:15)
at TLSSocket.socketOnEnd (_http_client.js:345:23)
at emitNone (events.js:91:20)
at TLSSocket.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9) code: 'ECONNRESET' }
IntelliJ produces this part when i'm running the script:
SSLSession :
Protocol : TLSv1.2
Cipher suite : TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
Inut : POST / HTTP/1.1
Inut : Connection: keep-alive
Inut : Content-Type: application/json; charset=utf-8
Inut : Content-Length: 24
Inut : Host: localhost:9999
Inut :
I hope you can help me because i don't know why i'm getting the error in i've tried several solutions but none of them has worked for me...
Thx and best wishes Martin
Assuming that you already have a HTTP server running on configured port, you will need to change host: 'localhost' to host: 'http://localhost'
It could either be http or https based on the protocol you have setup.
I am using Ratchet to create websockets for a chat and I get an error that says:
main.js:2 WebSocket connection to ws://localhost:8080/
failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
The code from which I get the error is the following:
$(document).ready(function () {
var conn = new WebSocket('ws://localhost:8080');
var chatForm = $(".chatForm"),
messageInputField = chatForm.find("#message"),
messagesList = $(".messages-list"),
usernameForm = $(".username-setter"),
usernameInput = usernameForm.find(".username-input");
I also changed the IP in the /etc/host to 0.0.0.0 just to be sure.
Anything you can suggest to change and fix this error?
I have the C# app that sends the UDP packets for the specific IP and port and it works well, because I have the other app that receives those packages. Now I would like to send them so that I can display it on my webpage - I've read that the node.js will fit perfectly here.
I installed the current version of node.js under windows environment and took the following code:
var PORT = 19777;
var MULTICAST_GROUP = "224.0.0.251";
var dgram = require("dgram");
var client = dgram.createSocket("udp4");
client.on("message", function(message, rinfo) {
console.log("received: ",message,rinfo);
});
client.on("listening", function() {
console.log("listening on ",client.address());
client.setBroadcast(true);
client.setTTL(64);
client.setMulticastTTL(64);
client.setMulticastLoopback(true);
client.addMembership(MULTICAST_GROUP);
client.send(payload, 0, payload.length, PORT, MULTICAST_GROUP, function(err,bytes) {
console.log("err: "+err+" bytes: "+bytes);
// client.close();
});
});
client.on("close", function() {
console.log("closed");
});
client.on("error", function(err) {
console.log("error: ",err);
});
client.bind(19777);
And now I started sending packets on the following ip "224.0.0.251" and port 19777 from my C# app - however, after runnint the client app I've got the following error:
C:\Users\user\Desktop>node client.js
error: { [Error: bind EADDRINUSE] code: 'EADDRINUSE', errno: 'EADDRINUSE', sysc
all: 'bind' }
What am I doing wrong? And - after fixing this issue - will I be able to just see all packets in the console? Thanks.
------------- EDIT:
Following the advice of John, I modified the app so that only node.js is listening now on that port. Thanks to this I made a progress and on the output of my console I get:
C:\Users\user\Desktop>node client.js
listening on { address: '0.0.0.0', family: 'IPv4', port: 19777 }
C:\Users\user\Desktop\client.js:19
client.send(payload, 0, payload.length, PORT, MULTICAST_GROUP, function(er
^
ReferenceError: payload is not defined
at Socket.<anonymous> (C:\Users\godyckim\Desktop\client.js:19:17)
at Socket.emit (events.js:104:17)
at startListening (dgram.js:139:10)
at dgram.js:230:7
at dns.js:85:18
at process._tickCallback (node.js:355:11)
at Function.Module.runMain (module.js:503:11)
at startup (node.js:129:16)
at node.js:814:3
but still no packets are visible.. Ok, I see that I didn't define the payload variable... What I want to achieve is to receive the packets that are sent by udp and either display it in the node.js console (that would be a start for me), or transfer it further so that I can see them in the browser. In the second case - what exactly I'm doing wrong now? Thanks!