Single port being disputed by multiple customers

Asked

Viewed 34 times

0

I am developing a solution for consuming a condominium box API in Nodejs, using the net library to make the communication. Our application makes direct communication with the condominium hardware and my biggest problem is that it provides only one door for communication (port 9001) and needs to be consumed by several clients ... The "single port" is a hardware constraint, so there are no ways to allocate other ports within the Guardhouse hardware, I need to find a way to develop on our side something that helps multiple customers consume the hardware data on that single port.

Follows the code of what has been developed so far:

//bibliotecas do node utilizadas:

let net 	= require("net");
let express = require('express');
let http    = require('http');
let cors    = require('cors');

let app         = express();
let server      = http.createServer(app);
let bodyParser  = require('body-parser');

app.use(cors());
app.options('*', cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser({limit: '800mb'}));

server.listen( 7979, function(){
    console.log("server listening to %j", server.address().port);
})
let client = net.createConnection(`9001`,`[link de acesso ao hardware]`)// Aqui o acesso é estabelecido na porta 9001 do hardware
	.on('error', (e) =>console.log('Erro de conexão', e));	


client.on("connect", function(data){
	console.log(`linear conectado porta: %j`, server.address().port);
});

client.on("data", function(data){
//Resposta da API	
});

client.on("end", function(data){
	console.log(`end: `);
	console.log(data);
});

app.get("/teste", (req, res) => {
//requisição feita pelo client
});

If there is a need I can provide more parts of the code (I believe this is enough because the biggest problem is the code of the variable 'client'). Does anyone know any solution?

  • 2

    For TCP protocol, that’s impossible. Internally the socket has a connection token, the operating system will not allow a socket that is not the holder of the token to receive the data. You can try to implement a proxy (tunnel) for port access, but you will have to adapt your applications and you will need hardware between the machine and customers. (

  • @Edney I understand, so is there any material I can read to better inform me about this proxy issue? Could I make the proxy just for the use of this function or everything I developed should be consumed through this proxy?

  • Basically you will have to make an application that receives requests and does the job that is needed on port 9001, it can have authorization mechanism, certificate, cache, etc. etc. This proxy will act as gateway to your resource, but without knowing better your environment can not say anything else. I recommend researching sockets and protocols, studying common processes such as http, ftp, ssl to have a base. This is more work than it seems. A example

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.