12345678910111213141516171819202122232425 |
- const io = require('socket.io-client');
- // Connect to the Socket.IO server
- // const socket = io('http://127.0.0.1:3000');
- const socket = io('http://127.0.0.1:3000/Sample-App');
- // Listen for the 'connect' event
- socket.on('connect', () => {
- console.log('Connected to the server!');
-
- // Emit a test event to the server
- setTimeout(() => {
- socket.emit('message', { message: 'Hello from the client!' });
- }, 3000)
- });
- // Listen for a 'test-response' event from the server
- socket.on('message', (data) => {
- console.log('Received from server:', data);
- });
- // Listen for the 'disconnect' event
- socket.on('disconnect', () => {
- console.log('Disconnected from the server');
- });
|