Add functionality to Socket.IO client
This commit is contained in:
parent
9a5c0b20ba
commit
33106da88f
1 changed files with 21 additions and 2 deletions
|
@ -1,8 +1,27 @@
|
||||||
import { io } from 'socket.io-client';
|
import { io } from 'socket.io-client';
|
||||||
|
|
||||||
function SocketIO() {
|
function SocketIO() {
|
||||||
// const socket = io("wss://server-domain.com");
|
const socket = io("ws://localhost:5001");
|
||||||
const socket = io(); // The server URL will be deduced from the window.location object.
|
socket.on('test2', (warst) => {
|
||||||
|
console.log('Test2:', warst, socket.id)
|
||||||
|
})
|
||||||
|
socket.on("connect", () => {
|
||||||
|
console.log(socket.connected); // true
|
||||||
|
setTimeout(() => {
|
||||||
|
socket.emit('test', "warst")
|
||||||
|
socket.emit('test', "tsra")
|
||||||
|
socket.emit('test', "1234")
|
||||||
|
// socket.disconnect()
|
||||||
|
}, 1000)
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on("test", () => {
|
||||||
|
console.log("Got test1234"); // false
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on("disconnect", () => {
|
||||||
|
console.log(socket.connected); // false
|
||||||
|
});
|
||||||
return (
|
return (
|
||||||
<div>SocketIO</div>
|
<div>SocketIO</div>
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue