Client connection on VPS hosting #4975
Unanswered
AleksandarNeustadt
asked this question in
Q&A
Replies: 1 comment
-
Hi! The port 3000 may not be open. Could you please check? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have created a small application that works locally, but now I have a problem when using it online on my VPS hosting with SSL.
When I start the server file, it shows a message that it is executing successfully.
Here is the code of the server file: app.js
`const fs = require("fs");
const PORT = '3000';
const { createServer } = require("https");
const { Server } = require("socket.io");
const httpsServer = createServer({
key: fs.readFileSync('./keys/keyone.key'),
cert: fs.readFileSync('./keys/crtone.crt')
});
const io = new Server(httpsServer, { /* options */ });
console.log(io);
io.on("connection", (socket) => {
// ...
});
// httpsServer.listen(3000);
httpsServer.listen(PORT, () => {
console.log(
Server running on port ${PORT}
);console.log(
Open https://localhost:${PORT} in your browser
);});
// When client exists
io.on('connection', (socket) => {
console.log('Client connected!');
// Send message
socket.emit('Message', 'Hallo from server!');
// waiting on message from client
socket.on('odgovor', (data) => {
console.log(
Client message: ${data}
);});
});`
But when I start index.html (client file), I fail to connect to the created server.
<title>WebSocket Client</title> <script src="https://cdn.socket.io/4.7.4/socket.io.min.js" integrity="sha384-Gr6Lu2Ajx28mzwyVR8CFkULdCU7kMlZ9UthllibdOSo6qAiN+yXNHqtgdTvFXMT4" crossorigin="anonymous"></script> <script> // client is on same domain const socket = io(); // in this moment pointing port 433 // const socket = io.connect('https://mydomainonvps:3000'); also not working console.log(socket); </script> `Here is the code of the client.
`
Message in console ist
a {connected: false, recovered: false, receiveBuffer: Array(0), sendBuffer: Array(0), _queue: Array(0), …}
acks
:
{}
connected
:
false
flags
:
{}
ids
:
0
io
:
s {nsps: {…}, subs: Array(3), opts: {…}, setTimeoutFn: ƒ, clearTimeoutFn: ƒ, …}
nsp
:
"/"
receiveBuffer
:
[]
recovered
:
false
sendBuffer
:
[]
subs
:
(4) [ƒ, ƒ, ƒ, ƒ]
_opts
:
{path: '/socket.io', hostname: 'mydomainonvps', secure: true, port: '3000'}
_queue
:
Array(0)
length
:
0
[[Prototype]]
:
Array(0)
_queueSeq
:
0
active
:
(...)
disconnected
:
(...)
volatile
:
(...)
[[Prototype]]
:
U
And
manager.js:108
GET https://mydomainonvps:3000/socket.io/?EIO=4&transport=polling&t=OuvFEWZ net::ERR_CONNECTION_TIMED_OUT
Can you tell me why this is happening and how to solve it (I feel like it might be related to the port)?
Beta Was this translation helpful? Give feedback.
All reactions