How to use the net module from Node.js with browserify? -


i want use net module node.js on client side (in browser):

var net = require('net'); 

so looked how node.js modules client, , browserify seems answer. tried jquery , worked charm. reason net module not want work. if write require('jquery') works fine, if write require('net') not work, meaning bundled .js file empty.

i tried search else, thing found net-browserify on github. this, @ least bundle.js file filled, javascript error using (it has connect function).

this code works on server side fine:

var net = require('net-browserify'); //or var net = require('net');  var client = new net.socket(); client.connect({port:25003}, function() {     console.log('connected');     client.write('hello, server! love, client.'); });  client.on('data', function(data) {     console.log('received: ' + data);     client.destroy(); // kill client after server's response });  client.on('close', function() {     console.log('connection closed'); }); 

i assume net-browserify lets use specific connect function, don't know which.

how can use net module node.js on client side?

this because net gives access raw tcp sockets - browsers cannot javascript end. impossible net ever ported client side until such api written (allowing arbitrary tcp traffic).

your best bet if want send tcp data client server using web sockets using socket.io module or ws one.

your best bet if want clients communicate directly webrtc


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -