I'm currently using Sockets.io to communicate with clients, sending JSON and whatnot, from a port.
That's all working good, but what i'd like to do is listen simultaneously on another port to create a type of administration page for testing purposes.
For example, the page would have a button to send a certain type of JSON for all the clients connected on the other port.
If this isn't ideal, any help on other simple solutions would be great.
You can't listen on multiple ports for a single http.
If you want to run NodeJS on different port, change 80 to your required port number (e.g 8080). Also the function defined in createServer() will be executed whenever someone sends a request to your NodeJS server. In this case, it simply returns “Hello World!” string.
No matter what size instance we use Node always appears to max out at 1000 concurrent connections (this is NOT 1000 per second, but 1000 it can handle at 1 time).
Listening on multiple ports on a single server 1 Start server; 2 Listen for incoming connections on several ports; 3 Identify the port being connected to; More ...
1. Start server; 2. Listen for incoming connections on several ports; 3. Identify the port being connected to; a. If port 1, start a thread listening to client and outputting message type x b. If port 2, start a thread listening to client and outputting message type y thanks in advance.
The server.listen () method creates a listener on the specified port or path. Optional. Specifies the port we want to listen to Optional. Specifies the IP address we want to listen to
Node.js allows developers to use JavaScript everywhere instead of just in browsers - the two big mainstream uses as of writing are web/app servers (Node.js is very well-suited for messaging-like applications like chat servers, for example) and Internet o Is Go killing Node.js? Maybe but I think Go has already taken its share from other languages.
Just create another instance of http and put it to listen to the port you are interested. Let me show you an example:
var http = require('http');
http.createServer(onRequest_a).listen(9011);
http.createServer(onRequest_b).listen(9012);
function onRequest_a (req, res) {
res.write('Response from 9011\n');
res.end();
}
function onRequest_b (req, res) {
res.write('Response from 9012\n');
res.end();
}
Then, you can test it (with your browser, or curl
):
$ curl http://localhost:9011
Response from 9011
$ curl http://localhost:9012
Response from 9012
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With