Websocket External
Websocket external is not built-in to GamanJS, what I mean here is that we just want to convey: GamanJS can also install other Websocket libraries, for example like socket.io and the like.
Socket.io
Section titled “Socket.io”Here I will give an example of a websocket library that is widely known by developers in the world, namely socket.io.
Install
Section titled “Install”GamanJS is a framework for backend applications, you can install using your favorite package manager:
npm install socket.iopnpm install socket.ioyarn install socket.iobun install socket.ioImplementation
Section titled “Implementation” import { Server } from 'socket.io';
defineBootstrap(async (app) => { const server = await app.mountSever(":3431"); const io = new Server(server); io.on('connection', (socket) => { console.log('a user connected'); }); });Client Side
Section titled “Client Side”<script src="/socket.io/socket.io.js"></script>
<script> const socket = io(); </script>