Git Product home page Git Product logo

node-tcp's Introduction

Node TCP Client Server

This is a basic tcp socket connect built on node js libarary. It connects 2 clients and trasfer messages between two clients until they are connect to each other. Once a client is disconnected, the other one will be informed that now you can't exchanges data stream with the other client. If the client again connects to the server then again both the clients can exchange the data streams between them.

Quick Start

  1. Clone this repo and install npm packages using npm install.
  2. Go to app directory and run server.js using node server.js.
  3. In different terminal go to app directory and run client using 'client.js'.
  4. Follow point 4 to run another client.
  5. Start sending messages from one client to another.
  6. Exit client/server using ctrl + c.
  7. Run the tests using npm test.

Specification

This module is built in the manner that there is a centralized server running on a port. To run that server go to app directory

cd node-tcp/app

and run

node server.js

if you see something like this in the server tab KEEP CALM THE SERVER IS UP AT 9000

Then your server is sucessfully running on the port 9000.

This will run the server on the port 9000 and will wait for clients to connect with it and make sockets.

Open new tab and run the client server.

cd node-tcp/app
node client.js

client tab will look something like this with a welcome message from server

You are connected to the server. Hope you enjoy your stay here!!
Try to send message to your friend if they are online they will see your message

Open another tab and run another client

node client.js

Now at this point we have a server running and two clients which have made sockets with the server. When you look at the server logs on server tab you will see something like this

KEEP CALM THE SERVER IS UP AT 9000

Connection received from 127.0.0.1:52469
Connection received from 127.0.0.1:52473

This means both the clients have made socket with the server and we are good to go for transferring messages between the clients.

Clients can write message in command like to other client like this CLIENT 1

You are connected to the server. Hope you enjoy your stay here!!
Try to send message to your friend if they are online they will see your message

Hey

The other client will recieve the message like this CLIENT-2

You are connected to the server. Hope you enjoy your stay here!!
Try to send message to your friend if they are online they will see your message

Your friend wrote: Hey

Now when some client get disconnected from server manually or by some other means then both client-2 and server will get notified about that like this SERVER

KEEP CALM THE SERVER IS UP AT 9000

Connection received from 127.0.0.1:52469
Connection received from 127.0.0.1:52473
connection from 127.0.0.1:52469 closed

CLIENTS-2

You are connected to the server. Hope you enjoy your stay here!!
Try to send message to your friend if they are online they will see your message

Your friend wrote: Hey
Your friend wrote: I am going offline and can't chat with you now.

When server is facing some downtime, the clients connected to the server will get notified like this

KEEP CALM THE SERVER IS DOWN!! TRY IT AFTER SOME TIME.

For running the tests you need to come back to base folder that is node-tcp and run

npm test

This will trigger the test file and will run all the test cases present in that file.

node-tcp's People

Contributors

prakharjoshi avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.