Node.js – Using Synchronous Sockets

javajavascriptmultithreadingnode.js

I want to port an existing app from Java to Node.js – would like to seek your advise.

The java app is a multithreaded socket server where arbitrary number of clients can connect. The app runs on java executors. Each client is given a socket to connect to the app.

The client will connect to the socket server and there will be handshake. After handshake, the data will be transmitted between the client and server. The data transferred is in sequential order because the client sends the data over as such. And I.m able to control the thread that the client is connected on.

Now, Node.js does not have threads so I am confused on how to port the multithreaded Java socket server over. Any ideas?

Best Answer

There isn't really any way to "port" the application. The best approach would be to model the existing behavior then write a completely new Node application that conforms to that behavior.

JavaScript and Java are hugely different programming models. JavaScript isn't strongly typed and relies heavily on an asynchronous programming model. Trying to do a direct port would give you awful code and you would lose out on a lot the features that make Node good.

Related Topic