Вы находитесь на странице: 1из 2

Basic chat application:

- chat system(bi-directional communication channel between client and server).

Web framework:
- setUp HTML webpage(form and list of messages)..and NODE.js web framework
express.
- install NODE.js
- create a package json //file that describes the project.
note:(to easily populate the dependencies with the things we need, we�ll use npm
install --save:)
-npm install --save express@4.15.2 //express is installed and we create an
index.js file to set up our application.
-express initializes app to be a function handler that you can supply to an HTTP
server.
then we define a route handler //called when we hit the website home, and we make
our http server listen on port 3000 //servesas an interface(com2com/peripheral
devices---available for connection to peripherals).

----Serving HTML---
note(index.js we�re calling res.send and pass it a HTML string)
- create an index.html file.

----Integrating Socket.io----
- socket.io integrates with(or mounts on)the node.js http server.
- socket.io-client is a client library that loads on the browser side.
note(socket.io serves as client automatically. We need to install the module and
add the dependency to package.json).
we have to initialize a new instance of socket.io by passing the (http server)
object. Listen on the connection event for incoming sockets, and log it to the
console. Then load the socket.io-client (exposes io global endpoint: GET
/socket.io/socket.io.js...then connect).
- if you use the local version of the client-side JS file, you can find it at
node_modules/socket.io-client/dist/socket.io.js.
If you now reload the server and the website you should see the console print �a
user connected�. It also fires a special disconnect event and you can also see " a
user disconnects".

----Emitting events-----
main idea is sending and receiving events you want(with your datas). Any objects
can be encoded as JSON and binary data will do.

----Broadcasting------
emit the event from the server to the rest of the users. (io.emit), broadcast flag
is needed if you want to send the message to everyone except for a certain socket.

-------------------------------------------------------
Homework---------------------------------------------------------------------------
-----------------------
Here are some ideas to improve the application:

Broadcast a message to connected users when someone connects or disconnects.


Add support for nicknames.
Don�t send the same message to the user that sent it himself. Instead, append the
message directly as soon as he presses enter.
Add �{user} is typing� functionality.
Show who�s online.
Add private messaging.
Share your improvements!
-----------------------------------My work-to-
do----------------------------------------------------------

Вам также может понравиться