I'm writing a TCP server application using NodeJS. However, each socket runs on a separate child-process (server.on("connection")). To send messages to specific clients, I used Emitter, and each socket generates its own listener (on clientID). So if there are 10000 connected devices, the application will create 10000 listeners. This looks terrible. What dangers will this pose? I can't find a solution to send a message from one client to another in the TCP protocol writing NodeJS code. Update: Have any idea to send message to specific client without add custom listeners?
What does it matter if there are many nodejs emitter listeners?
167 views Asked by Huy Quoc At
1
There are 1 answers
Related Questions in JAVASCRIPT
- Using Puppeteer to scrape a public API only when the data changes
- inline SVG text (js)
- An array of images and a for loop display the buttons. How to assign each button to open its own block by name?
- Storing the preferred font-size in localStorage
- Simple movie API request not showing up in the console log
- Authenticate Flask rest API
- Deploying sveltekit app with gunjs on vercel throws cannot find module './lib/text-encoding'
- How to request administrator rights?
- mp4 embedded videos within github pages website not loading
- Scrimba tutorial was working, suddenly stopped even trying the default
- In Datatables, start value resets to 0, when column sorting
- How do I link two models in mongoose?
- parameter values only being sent to certain columns in google sheet?
- Run main several times of wasm in browser
- Variable inside a Variable, not updating
Related Questions in NODE.JS
- Using Puppeteer to scrape a public API only when the data changes
- How to request administrator rights?
- How do I link two models in mongoose?
- Variable inside a Variable, not updating
- Unable to Post Form Data to MongoDB because of picturepath
- Connection terminated unexpectedly while performing multi row insert using pg-promise
- Processing multiple forms in nodejs and postgresql
- Node.js Server + Socket.IO + Android Mobile Applicatoin XHR Polling Error...?
- How to change the Font Weight of a SelectValue component in React when a SelectItem is selected?
- My unban and ban commands arent showing when i put the slash
- how to make read only file/directory in Mac writable
- How can I outsource worker processes within a for loop?
- Get remote MKV file metadata using nodejs
- Adding google-profanity-words to web page
- Products aren't displayed after fetching data from mysql db (node.js & express)
Related Questions in TCP
- Java SocketException: Connection reset,. What is the cause?
- How does a server handle multiple requests, and how does is know where to send which response?
- How does pre-allocating a pool of SocketAsyncEventArgs objects upfront improve the performance of a server application in c#
- How to peek or ready to check whether HTTP request or not in TCP proxy?
- How does bash > /dev/tcp/"ip"/"port 0<&1 keep its connection alive?
- Python TCP Server that both sends and or receives data (independently) using asyncio streams?
- Can't remotely connect to my postgresql database on digitalocean
- Why my message doesn't write into the socket when I try to read the response after sending it?
- What makes MQTT a raw tcp connection that we can't run it in the browser?
- ImGui rendering wrong characters (characters received from tcp sockets)
- TCP/IP Server Using sockets Java
- C# tcp socket keepalive I want to visit a website, but the specified time is very slow and I cannot access it
- Java TCP socket want to multiple times input with one connection
- How do I receive TCP messages on an android Emulator from a physcal device
- Getting error while using the MessagePattern to communicate between microservices
Related Questions in EMITTER
- Ngxs state with emitter problem with sonar test - state was used before it was defined?
- How to use the OpenFaas 'mqtt-publisher' with FaasD
- How to play a specific frequency sound?
- How to Store an Emmiter.io received messages in a Variable and send as props
- Communicating using receiver node in webots
- Why event listener "pause" execution of async function to start new execution?
- What does it matter if there are many nodejs emitter listeners?
- PHP Emitter for socket.io v4
- Particle stutters the first time it is spawned (UE4)
- How to launch sparkEmmiter (created custom smoke.sks file) in the view? Swift 5
- What are the typical values for the three inputs to the Driver circuit board of Infrasolid's thermal emitters in Hispower series?
- Adding different objects to CAEmitterLayer with forEach with SwiftUI
- Spring Web-Flux Server Sent Events is not working when using IP for local and remote calls
- Cannot Click UIButton When Particle Emitter Is On Screen
- Communication webots emitter and receiver
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Popular Tags
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Why would you do that? The core idea behind NodeJS is to run things in an event loop. Single threaded, yes, but asynchronous.
It is terrible. The biggest issue is that you sacrifice a lot of resources. You not only spawn thousands of processes but you also spawn lots of emitters. So first of all this means lots of RAM eaten. Secondly this means degraded performance due to process context switch, which typically is slower than user space switch. Assuming your machine will even allow you to spawn so many processes.
I assume you have a TCP server, two connected clients and client A wants to send message to client B. Is that correct? TCP by itself won't do that for you. You need some protocol on top of it. For example:
(username, password)pair to the server. The server validates the pair. The server keeps a global mapping{"<username>": [sockets]}and adds newly authenticated client to that mapping.{"type": "direct", "destination": "clientB", "data": "hello B"}. The server parses the message and forwards it to the appropriate client (taken from the global mapping).In case when you want to broadcast the message you send say
{"type":"broadcast", "data": "hello all"}kind of message. The server then parses it, it loops through all connected clients (found in the global mapping) and forwards the message to each client.Of course you also need some framing of packets. Since TCP is a stream, then it doesn't really understand messages and where one starts and the other ends. Dumping things to JSON is a half of the problem. Because then you have to send this JSON over the network and the other side has to know how many bytes it has to read. One way is to prefix each message with, say, 2 bytes that tell the other side how long the message is.
Btw you may want to consider using socket.io (or some other lib) that take care of some of those tedious details for you.