It is possible to create a TCP Server that will handle the connection with the Client along with a Web Server using express that will have functions like start, stop and Restart tcp server?
Yes, it is possible. For this you need to initialize a TCP System:
var net = require('net');
var server = net.createServer();
server.on('connection', handleConnection);
server.listen(9000, function() {
console.log('server listening to %j', server.address());
});
function handleConnection(conn) {
// [...]
}
(Partial example of https://blog.yld.io/2016/02/23/building-a-tcp-service-using-node-js/#. Wtytdwjythe )
If it’s possible, I should do it?
It will depend exclusively on your modeling. You may be wanting to write a compact solution, where listeners HTTP + TCP can co-exist - or a service-separated implementation.
3rd Is there an ideal structure for folders and files for a tcp server? Can I apply the MVC concept?
Again, the answer depends on your modeling. I confess that I have a certain difficulty in visualizing a folder model for a TCP solution, since we are talking about a stream. If you’re referring to the classes, there’s another chat.
As for the MVC model, yes, there are several Nodejs modules that adopt this model. Since net.createServer() has to do with state maintenance, I would say yes, the controller layer would be a good host candidate of the connection control features.