'socket.io connection not working but new Websocket working
I' have a socket server i just try to connect that server.
when i try new Websocket my connection is works;
const socket = new Websocket('ws://127.0.0.1:8000');
but when i want to use socket.io like this;
const socket = io('ws://127.0.0.1:8000');
socket.on('connect', () => {
console.log('connected');
});
socket io code can't connect to socket it's fired cors error everytime but new Websocket connection works easly.
I found a solution like this;
socket = io('ws://127.0.0.1:8000', {
"transports": [
"websocket"
]
});
i added transports datas then socket start works.
Solution 1:[1]
This worked for me
socket = io('ws://localhost:8000',{transports:['websocket']});
Thanks @Ugurcan
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Saumya Prakash |