Reputation: 441
I have a simple node application that sends data through tcp sockets. Essentially it’s two node applications a sender and a receiver, or a client and server. I can open two terminal shells on my localhost and see data transferring though tcp sockets, so I know it works. I want to send data from my localhost to my server with these applications but I can’t figure it out.. wether its the ip address routing or if I have to open tcp ports or disable firewalls, not sure. here's what the server and client apps look like when I can successfully send data on my localhost. I want to use this client app on my localhost and host the server app on my centos server and transfer data, is this possible?
/*** TCP Client ***/
/* Dependencies */
var fs = require('fs');
var hl7 = require('simple-hl7');
/* Build TCP Server */
var server = hl7.Server;
var tcpClient = server.createTcpClient();
/* Connection */
tcpClient.connect('127.0.0.1', 6969);
/* Get XML */
var msg = fs.readFileSync('./data/example.xml').toString();
/* Send Message */
setTimeout(function() {
tcpClient.send(msg, function(ack) {
console.log("ACK: ",ack.toString());
console.log("\nsuccessful transfer");
tcpClient.close();
});
}, 500);
the server can be found here. click here but heres the config code..
/*
Config class
vars:
baseFolder: Where to save the messages
port : What port to listen on
ip : what ip to listen on
*/
var Config = new function() {
this.baseFolder = "data";
this.port = 6969;
this.ip = '127.0.0.1';
}
Upvotes: 1
Views: 2023
Reputation: 4804
Ofcouce it is possible. Set server's IP and listening port in client. Then since client gonna connect to server, you will have to open this port on the server in both directions. And then just connect.
Basically here tcpClient.connect('127.0.0.1', 6969);
Instead of 127... should be server's real external IP address.
Upvotes: 0