I created a very simple Node.JS script which is suppose to connect to a server on port 3200. The code works great on Windows 8.1 x64, but when I moved it to a Ubuntu Server machine I am getting a ECONNREFUSED.
I tried to connect via IP Address and the Domain Name, but neither work. It always gives me ECONNREFUSED.
When I SSH into the Ubuntu Server I can do a telnet to the server/port and it works fine. Also pinging the server works. Just Node.JS doesnt connect.
Server:
Ubuntu Server 12.04.3 LTS (precise)
Here is the code:
var net = require('net');
var socket = net.connect({port: 3200, host: '172.19.16.203'}, function() {
// Connection Successful
console.log('Socket connected...');
// Data Received from Server
socket.on('data', function(d) {
console.log('data');
});
socket.on('end', function() {
});
socket.on('error', function(e) {
});
});
I found the solution. I was running my script by the following command:
node test.js
I guess the node is an old version. I upgraded the OS to the latest version and then did:
apt-get install nodejs
I run the script like following:
nodejs test.js
And it works!
Related
I have a redis server which is working fine in my local but in ubuntu server is not working can someone gives the comment for installing redis in server
it is not working even with docker it is working only while i am running in local
const redis=require('redis');
var redisClient:any;
(async () => {
try {
redisClient = redis.createClient({ socket: { port: 6379 } });
await redisClient.connect();
// const redisClient = redis.createClient({
// port:"6379",
// host:'redis-service'
// });
redisClient.on('connect',()=>{
console.log('server connected to redis')
})
redisClient.on('ready',()=>{
console.log('Client Connect to redis and ready to use')
})
redisClient.on('error',(err:any)=>{
console.log(err)
})
redisClient.on('end',()=>{
console.log('Server disconnected from redis')
})
process.on('SIGINT',()=>{
redisClient.quit()
})
console.log('connected');
} catch (err) {
console.error(err)
}
})()
export{
redisClient
};
Make sure that Redis is not already running on the server. You can check this by running the command ps aux | grep redis. If Redis is running, you should see a line with the redis-server process.
Confirm that Redis is properly installed on your server by running redis-cli ping. If Redis is installed and running, it should return "PONG"
Check the Redis configuration file (redis.conf) and ensure that the IP and port settings match the settings on your local machine.
Make sure that the Redis server has the necessary permissions to access its data directory and that the correct ownership and permissions are set on its files.
Verify that the firewall rules on the server allow incoming connections on the Redis port (usually 6379)
Check for any compatibility issues between the version of Redis that you're running on your local machine and the version of Redis that's running on the Ubuntu server. If there's a version mismatch, it may be necessary to upgrade or downgrade one of the installations.
Try to run the Redis server with verbose output by running the command redis-server -v, this can give you some more information about the errors that are causing the server to fail.
Look at Redis log files, usually located in /var/log/redis for further clues about the cause of the problem.
I have deployed node API on Ubuntu server (AWS) but when I run my app it throw below error given in screen shot. due to I am not able to make API requst.
I have trid to kill port and execute it again but it gives e same error
my node app is running on 8081 on local machine
var connection = mongoose
.connect(url, option)
.then(result => {
app.listen(PORT);
console.log("Running RestHub on port " + PORT)
})
.catch(err => {
console.log(err);
});
after uploading code in Ubuntu sever it does not work
I am struggling to fix this issue since yesterday but could not fix yet.
Please your help would be highly appreciated
Thanks you
I am trying to create a Socket server, but I keep getting ECONNREFUSED when I try and launch the server.
var net = require('net');
var server = net.createConnection(3000,'localhost',function(socket) {
console.log('connected!');
});
server.on('error', function(e) {
console.log(e);
});
Nothing fancy.
However when I try to run it node server.js, I only get an error message. Is there a step I am missing here? Is it maybe a configuration issue?
I am running node 0.10.32 if that helps.
Thanks
That error is your client cant connect to server. You can add this code to snip error.
server.on('error', function(err){
console.log(err.message);
});
Did your server start ? You can use http.createServer to create server listen on port 3000 and you connect to it.
I have a telnet server embedded in a C++ app that I can connect to with no problem
using telnet.
I want to write a node application that will connect to my server and I have tried
this
var net = require('net');
var port = 6502
var host = '127.0.0.1'
var socket = net.connect(port,host, function() {
console.log("Sending data");
socket.write("hello\r\n")
socket.on("data", function (data) {
console.log("received data");
console.log( data.toString() );
socket.end();
})
})
socket.on("error", function(err) {
console.log("Error");
console.log(err);
})
Unfortunately what I get back is this
> node test.js
{ [Error: connect ECONNREFUSED]
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect' }
What's really odd is if I set up a simple echo server with node everything works
fine. Here's the working echo server code:
var net = require('net');
var server = net.createServer(function (socket) {
socket.write('Echo server\r\n');
socket.pipe(socket);
});
server.listen(6502, '127.0.0.1');
and from that I get
Sending data
received data
Echo server
hello
Is there any reason why:
I can telnet into my app fine
I can connect from node to my node echo server on the same port
I get a connection refused if I connect from my node app to my app
Extra Info
On OSX (mavericks)
Node version 0.10.28
Telnet server in C++ is provided via embedded lua and luasocket (lua 5.1)
Solved!
The issue is the code in my app server was binding to localhost and by default
that binds to the IPV6 address of ::1
Passing a host of localhost to net.connect assumes IPV4 and doesn't work.
The mac command line telnet and nc both work fine with this and connect correctly.
Two solutions:
App binds to 127.0.0.1 and localhost in node works fine
Set host address to ::1 in test.js and it connects via ipv6
All fixed now though :)
gaz
Looks like you forgot to tell the server to listen in your code. It throws a connection refused error because there is nothing to connect to...
Add this at the end: server.listen(port);
The prototype for net.connect is (options, callback)
See http://nodejs.org/api/net.html#net_net_connect_options_connectionlistener
I would then suggest to test your code against a standard telnet server to see how it behaves, and finally I would strongly recommend the use of jshint or jslint.
This is the first time I am getting this error using nodejs, not sure what is it and how to come out of it. Below is the error:
node: symbol lookup error: /home/zishan/node_modules/zmq/build/Release/zmq.node: undefined symbol: zmq_sendmsg
when I am getting above error:
I have two test scripts testServer.js and testClient.js, when I am running testServer.js it's working fine but when I am running testClient.js by node testClient.js than testServer.js node window immediately throws above error.
below is the code for both scripts.
// testServer.js
var zmq = require('zmq');
var socket = zmq.socket('push');
socket.bindSync('tcp://127.0.0.1:3000');
console.log('Server is open on port 3000');
setInterval(function(){
console.log('sending work');
socket.send('some work');
}, 500);
Below is testClient.js
var zmq = require('zmq')
var socket = zmq.socket('pull');
socket.connect('tcp://127.0.0.1:3000');
console.log('client connected to port 3000');
socket.on('message', function(msg){
console.log(msg.toString());
});
My Env.
Ubuntu - 13.04
Nodejs - 0.10.24
Recently i reinstalled node using How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X) because i got hit by this error node-gyp rebuild.
Any help is much appreciated.
Can you try uninstalling latest zmq module by npm uninstall zmq and try with specific version of zmq npm install zmq#2.4.0