node js network programming | nodejs tutorials

 tcp 

node js server programming using tcp

on socket - we will host our applicaitons

and at the other end on telnet - we wil  raise request

telnent transfered by tcp to socket - raise teh request - resolve at asocket


for this purpose we import net

create  a server with socket


server.js

var net = require("net");
console.log('vamsi');
var server = net.createServer(function(socket)
{
socket.end("Hello and good bye");
}

);

server.on("error", function(error){
if(error.code ==='EADDRINUSE')
{
console.error("port is already in use");
}
})
server.listen(1234, function (){
console.log("server started");
});


if server is on 

it below programm run otherwise port is not running like that areror  displays

var net = require("net");

var client = net.connect(
{
port :1234,
host: "localhost",
}, function (){
console.log("connection establieshd");
}
);

client.js





conenct to port 1234


in bleow programming

after server started

connected print

then at aclient side write json messange on client side

if any change in file modfication time 

fs.watch - it watch continuosly

if modified - write 

changed  into file 

if client is disconnected it will print disconected


fs.watch

connectin.write

connection.on

server.js
 


run node server.js data.txt

it will write int data.text

file


node client.js

write into file

echo >>data.txt

conect between client and server




No comments:

Post a Comment

Event listening in react

 How we can listen to som eevents some envents fire like click or automatically user enters into input button , that is event on word type i...