io-service
Socket.io based web framework.
Installing
npm install io-service
Hello World
Server side
const App = const app = app app
Client side (Using Socket.io client library)
const socket = socketsocket
connect
and disconnect
events
The The connect
event is called when a socket client is connected
app
The disconnect
event is called when a socket client is disconnected
app
Using middlewares
You can create middlewares creating events with the same path and calling the next()
method to call the next middleware.
app app
Or loading a series of middleware functions at a mount point, with a mount path.
app
Unsing routers
A router object is an isolated instance of middleware and routes. You can think of it as a “mini-application,” capable only of performing middleware and routing functions. Every Express application has a built-in app router.
index.js
const App = const users = const app = app
users.js
const Router = const router = router router router router moduleexports = router
Client side
socketsocketsocketsocket
Serving static files
const app = static: 'path/to/static/files'
Serving over HTTPS
const app = httpsOptions: key: fs cert: fs
ctx
object
The - socket: The connected socket
- path: The request path
- body: The request body
- packet: The request packet
- next(): Function to call the next middleware