I am trying to bridge a websocket to a socks5. Basically I created a websocket server that listen to request and turn into
const socket = net.connect(port, host, ()=>{
socket.write(Buffer.from(buf));
});
Now I tried using proxysocket and do
const socket = proxysocket.create(proxy_host, proxy_port);
socket.connect(port, host,()=>{
console.log('hi');
socket.write(Buffer.from(buf));
});
Yet it never gets to 'hi'.
Related
I create app with nodejs socket io. It works clearly at localhost (port: 3000). But when i deploy it to my server in there i can run my app on 3000 port but client side throw timeout. How can i solve it?
var fs = require('fs');
var https = require('https');
var options = {
key: fs.readFileSync('ssl.my-key.key'),
cert: fs.readFileSync('ssl.my-cert.crt')
};
var server = https.createServer(options);
var io = require('socket.io').listen(server);
var port = 3000;
const database = require('./Database');
io.on('connection', (socket) => {
socket.on('message', async (msg) => {
// I do some action here.
});
socket.on('disconnect', (msg) => {
// some action in here too
});
});
server.listen(port, () => {
console.log('listening on *:' + port);
});
It seems like your issue is with port forwarding.
In order for your server to be publicly accessed, it needs to have all ports forwarded appropriately. Locally and on the router.
Check this link to learn more about how to port forward on linux: https://linuxacademy.com/guide/11630-internal-port-forwarding-on-linux-using-the-firewall/
And this to learn more about router port forwarding, but this will really depend on your router.
https://www.noip.com/support/knowledgebase/general-port-forwarding-guide/
However, I don't recommend you to take care of hosting on your own machine(s). I
suggest you use Heroku, you can op in for their free servers, you don't need to pay.
More about heroku and NodeJS: https://linuxacademy.com/guide/11630-internal-port-forwarding-on-linux-using-the-firewall/
let we debug your node js app.
1) add some logs on database connection, http.createserver, also where you have to check if not success then catch exception
2) you should have to open port on centOs before start your node js app
3) you should have test you with domain name or ip address
as per you comment you got connection timeout , you mean node js server trying to connect with port 3000 but node not able to connect and its throws error with connection timeout
also send your sample code of your main index file so we can investigate your problen
thanks.
I have managed to create a TCP server using node.js which looks something like this.
const net = require('net');
const port = 7070;
const host = '127.0.0.1';
const server = net.createServer();
server.listen(port, host, () => {
console.log('TCP Server is running on port ' + port + '.');
});
I am wanting to create a http rest API wrapper around this. So that I can send messages from my TCP server to my TCP client. For example if I create a URL http://example.com/api/send-message and when I hit this URL it will trigger my TCP server to send a message.
I'm just so confused as to how I can even go about doing this as the TCP server and REST API server are on different ports. Please can anyone help
I managed to solve this by creating a node.js app that acts as a tcp client that talks to my node.js tcp server. In the client I integrated express. Express creates the API and then on each endpoint I created a TCP connection that communicates with my TCP server and then the response is sent back to my http API
const express = require('express')
const app = express()
const port = 3000;
const net = require('net');
const client = new net.Socket();
var tcpPort = 7070;
var tcpIP = '127.0.0.1';
app.get('/',function(req, res){
client.connect(tcpPort, tcpIP);
client.write('Hello world');
client.on('data', function(data) {
client.destroy();
res.send({hello:data.toString()});
});
});
I am trying to create a net socket Nodejs server for my embedded device to send data to on OpenShift.
I am trying to create this simple echo service
var net = require('net');
var HOST = process.env.OPENSHIFT_NODEJS_IP;
var PORT = process.env.OPENSHIFT_NODEJS_PORT || 3000;
console.log('IP:' + HOST + ' Port:' + PORT);
var server = net.createServer(function(connection) {
console.log('client connected');
connection.on('end', function() {console.log('client disconnected');});
connection.write('Hello World!\r\n');
connection.pipe(connection);
});
server.listen(PORT, HOST , function() {
console.log('server is listening');
});
I according to OpenShift's Port Binding Guide I had my client application connect to Port 8000.
For Testing I am using the following code from my desktop machine.
var net = require('net');
var HOST = 'nodejs-myapplication.rhcloud.com';
var PORT = 8000;
var client = net.connect(PORT, HOST, function() {
console.log('connected to server!');
});
client.on('data', function(data) {
console.log(data.toString());
client.end();
});
client.on('end', function() {
console.log('disconnected from server');
});
The Client Scripts gets to Connected to server and gets stuck there itself. Nothing takes place after that.
Now if I open the address nodejs-myapplication.rhcloud.com:8000 in my browser, the NodeJS Server logs a client connected and disconnected, but when the NodeClient is connected the server doesn't show any update. The Node Client just says connected and stays there without doing anything.
If I run the same scripts locally it works fine, ( Locally i use HOst as 127.0.0.1 and port as 3000).
How can I get a TCP Application to connect to the Openshift NodeJS Server?
The Device will be sending ASCII output over the socket eg. $VAR,12,23,21\r\n
I need to be able to read that data, convert it to JSON and send it out to another server.
It has to be loaded on a platform like DigitalOcean with a firewall enabled.
OpenShift doesn't allow custom ports by default so need a workaround for that.
I have webrtc node server like as below.
var WebSocketServer = require('websocket').server;
var http = require('http');
var server = http.createServer(function(request, response) {
// process HTTP request. Since we're writing just WebSockets server
// we don't have to implement anything.
});
server.listen(1337, function() { });
// create the server
wsServer = new WebSocketServer({
httpServer: server
});
// WebSocket server
wsServer.on('request', function(request) {
var connection = request.accept(null, request.origin);
// This is the most important callback for us, we'll handle
// all messages from users here.
connection.on('message', function(message) {
if (message.type === 'utf8') {
// process WebSocket message
}
});
connection.on('close', function(connection) {
// close user connection
});
});
I wonder that which port range is used by node server. We can see one port in the code (1337). But i think node server uses one more port or port range because of video stream. How can i learn which ports are used by webrtc node server.
The Node.js server does not use any additional ports for media. It is a signalling server which only relays session information(SDP exchange, ICE, etc.) and does not relay any media.
If the media was to be relayed by anything, it would be a TURN server but that would be determined by your ICE server set up.
Now, if you are handling media in a peerconnection on the same server as you are signalling, you can grab the port that the media is being streamed to the peerconnection from the SDP.
I'm integrating socket.io into my project. I'm using the code below and it's creating 6 connections after the first request. Is this normal?
server.listen(
port,
function()
{
console.log('Node.js server listening on port ' + port);
}
);
server.on(
'connection',
function(socket)
{
console.log('socket.io connection');
}
);
And here is the console.log output:
Node.js server listening on port 3000
socket.io connection
socket.io connection
socket.io connection
socket.io connection
socket.io connection
socket.io connection
You get this result because (as far as I understand) your server object is an instance of node's http.Server class, and is not connected with Socket.IO at all. In your example, 'connection' event is being fired on any request the your node server. It looks like browser sends 6 requests to your node server: page, favicon.ico, and 4 other requests (it might be images, javascripts, css, etc.).
To integrate socket.io into your project you may use the following code:
var http = require('http');
var sio = require('socket.io');
var server = http.createServer(function(req, res) {
//you request handler here
});
var io = sio(server);
io.on('connection', function(socket) {
console.log('socket connected');
//now you can emit and listen messages
});
var port = 3000;
server.listen(port, function() {
console.log('Node.js server listening on port ' + port);
});
And, of course, the official documentation might be very helpful. Good luck :)