1

In all the examples of creating a client for node.js built-in net module I don't see how they get net to run on the client with out downloading it??

surely if my client-side code starts like this:

var net = require('net');
var client = net.connect({port: 8124},function(){
   console.log('client connected');
   client.write('world!\r\n');
   });

then first i must write:

<script src="some strange node path to net ??"></script>

am i correct? how do I do this? btw: node.js is installed in my root on my server not local

9
  • 1
    What are you trying to achieve? Call a node server from a browser, or from another node instance? Commented Nov 18, 2013 at 17:57
  • i want to talk: client to server and vice versa Commented Nov 18, 2013 at 17:58
  • not with socket.io (i don't like voodoo) i want to understand by building something simple myself Commented Nov 18, 2013 at 17:59
  • Are you asking where the net module is stored? Commented Nov 18, 2013 at 18:09
  • yes and also how to use it to ceate the client in the browser for two way communication... im also looking at ajax and the http module scratching my head! Commented Nov 18, 2013 at 18:26

1 Answer 1

2

I believe there's a bit of confusion here. The client example code you're showing is meant to run in node, not in the browser. That makes node a client of another (node or otherwise) TCP server.

If you want node to be the client and connect to another server over TCP, then run the code you're pasting. The net module is bundled with node, you're good to go.

If, however, you want your browser to talk to a node server then this would have to be over websockets (a streaming binary protocol over http, this is not plain-vanilla TCP). You would have to have a websockets module in the server, not plain net.

Just to be clear: net is simply node's interface to TCP sockets.

Sign up to request clarification or add additional context in comments.

2 Comments

I am very confused because of one web page rhuno.com/flashblog/2011/05/22/… (btw, I am not intending to use flash). all i see here is 1) bidirectional communication. 2) only net module. Someone please explain how. This is messing my head up! google says nothing on stupid asp.net stuff nothing for node.js unless you want express or socket.io
btw: that is page 2 of 3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.