-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
22 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Simple ChitChat | ||
|
||
This is a simple chat made with Socket IO, the client automatically generates an ID for the user, and uses it during its current session. | ||
|
||
It's made as a simple demo for the most basic features of socket IO so little to no security measures are taken into consideration. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,20 @@ | ||
# Socket IO practice | ||
|
||
This is a simple chat made with Socket IO, the client automatically generates an ID for the user, and uses it during its current session. | ||
Something to showcase socket IO usage in action. | ||
|
||
It's made as a simple demo for the most basic features of socket IO so little to no security measures are taken into consideration. | ||
## Basic server workflow | ||
|
||
- You start by creating an instance of Socket IO server, it can be connected to an http server you created like done here, or working on its own. | ||
- Socket io is event driven so the flow is mainly driven by the `on(eventName, handler)` function, that simply handle and event with a given name, by a given function. | ||
- And the most important event is the `connection` event that's where you | ||
- identify the client | ||
- Add them into a room | ||
- set the events of interest of that client to keep it updated with messages on those events that are meant for them. | ||
- There is surely authentication in socket IO, its data is sent from the client and is accessible from `handshake` field of the socket. for security it's passed on the `auth` field inside it. | ||
- We may add a middleware on a socket server using the `use` function, similar to express. except it takes `socket`, and `next` as inputs, but works intuitively enough as you'd expect, if not pay a visit for the docs. | ||
|
||
## Basic client workflow | ||
|
||
- Similarly, you would create a socket io client that connects to the server providing the credentials in the options if required. | ||
- Then the client would provide handler for the events its interested to listen on. | ||
- The client can also send messages using the `emit` function (actually similarly can the server). |