I have multiple Node.js servers running on an Amazon Web Service application. One of the servers is being ran on port 8080. How do I connect to this port?
Using var socket = io.connect('example.region-1.elasticbeanstalk.com') connects me to the primary server. What I need is something like var socket = io.connect('example.region-1.elasticbeanstalk.com:8080').
Related
The server app was running quite fine on Heroku but after migrating to Azure the server would not just start.
Here is the code..
const PORT = process.env.PORT || 2498;
const INDEX = '/index.html';
const server = express()
.use((req, res) => res.sendFile(INDEX, { root: __dirname }))
.listen(PORT, () => console.log(`We\'re live on channel : ${PORT}`));
const wss = new Server({ server });
wss.on('connection', (ws) => {
console.log('Client connected');
ws.on('close', () => console.log('Client disconnected'));
ws.on('message', (message) =>{
// this stays within the server
console.log('[SERVER]: Received a message => %s', message );
})
})```
.........
Clients connected are returning not establish an handshake ....
Azure web app only supports the exposure of port 80 and 443 for website access.
My previous requirements and test results:
I think your problem is a typical problem. I also had related requirements before, and the test failed in the webapp. All documents of Azure app service, talking about websocket, all use SignalR. I also tested the signalr service and it was successful, but this service is free and currently only supports 20 client connections.
What I thought before was to create a console program and put it in webjob to let webjob provide websocket service, but it all failed in the end.
Because azure webapp runs in a sandbox environment, and only open ports 80 and 443, we can't do more configuration. Obviously, the port that your websocket service starts is 2498, so it is not supported.
Suggestion
If you must use websocket, regardless of programming language, you must support custom port opening, such as using Virtual Machine.
You can compare the charges of azure cloud service and virtaul machine. Which one is right for you and which one to use.
Another suggestion is that you can buy a third-party intranet penetration tool and use a fixed IP or URL, such as ngrok, so that you can put the websocket service on your company's internal server. (The test is valid).
Of these three options, intranet penetration may be the most cost-effective choice. You can choose according to your needs.
I'm trying to host a Websocket server on my heroku app. There already is a GraphQL server running, but I don't think it's the cause of my problem.
So my server is started like this
const wss = new ws.Server({ port: port }, () => console.log(`Serveur WebSocket prĂȘt ${port}`));
There is no error, but when I try to connect to the server in my browser, just like this :
const ws = new WebSocket('wss://ethyme-api.herokuapp.com/');
I get an error 404.
So my question is, what is the path of the ws server, so I can connect to it ?
Thanks
If your Heroku app is called ethyme-api and and your locally run application is available under ws://localhost:$PORT/ the websocket will be available under wss://ethyme-api.herokuapp.com/ and ws://ethyme-api.herokuapp.com/
I am able to connect a web based app to a socket.io server, but not a terminal based app, this is what i use to connect to the socket.io server:
var socket = require('socket.io')
var connection = socket.connect('http://127.0.0.1:8080');
I get the following error:
TypeError: socket.connect is not a function
How can I connect a terminal app to a socket.io server, written in node.js
The socket.io is for creating WebSocket server. You can't use this module as a client. Instead try socket.io-client
var socket = require('socket.io-client')('http://127.0.0.1:8080');
socket.on('connect', function(){});
socket.on('event', function(data){});
socket.on('disconnect', function(){});
I would like to know if is possible create a server using express without serving any port. I need create a server just for socket connection with other application using TCP protocol.
Maybe express is not the best tool for that? Cause express is for web frameworks, and i don't really need ANY port at all.
Currently i'm doing:
http.createServer(app).listen(8000, function() {
console.log('Connected in port 8000');
});
Thanks.
If you're not going to have an http server listening for incoming HTTP connections, then you don't even need an Express server at all since it is a web server framework. No need to use the Express framework at all.
Instead, you can just use the built-in net module and use plain TCP socket functions in that module (see here for creating a plain TCP server). If you are going to be listening for incoming TCP connections, you will still need to be listening on a specific port - that's how TCP works. An incoming connection connects on a specific port and it must connect to a server listening on that specific port.
I need to build a socket.io server that will intercept incoming connections from an app which is not stored in the same directory as the server.
The client side app does not contain node.js, thus I'm trying to use a websocket :
Telnet.Socket = new WebSocket('ws://127.0.0.1:3000');
My node.js server does not need a http server but must be a standalone socket.io app. Thus, I've tried the following code :
var io = require('socket.io')();
io.on('connection', function(socket){
console.log('connexion entrante');
});
io.listen(3000);
Unfortunately, the server part does not seem to get the Websocket connection request. My firefox says :
Firefox cannot establish a connection with the server at adress ws://127.0.0.1:3000/.
What am I missing ?
Thx in advance !
socket.io need client use socket.io to connect because it use many kind of connection. For connect websocket only you can use ws node module