'Socket.IO cannot establish a connection

I use socket.io-client for Javascript server on JAVA and when I enter address 'ws://10.201.223.67:9902/' the request is not by 'ws' but by 'http'. enter image description here

It returns enter image description here

Although I understand it should just come back 0 enter image description here

It keeps trying to connect.To connect using my own written hook

export function useSocketIO(url: string) {
const ioRef = useRef<Socket>();
const [connected, setConnected] = useState(false);

useEffect(() => {
ioRef.current = io(url, {
  transportOptions: {
    polling: {
      extraHeaders: {
        Authorization: `Bearer ${APIAuth.accessToken}`,
      },
    },
  },
});
ioRef.current.on('connect', () => {
  console.log('WS Connected to', url);
  setConnected(() => true);
});

ioRef.current.on('disconnect', () => {
  console.log('WS disconnected');
  setConnected(() => false);
});

return () => {
  console.log('WS destroyed');
  ioRef.current?.close();
};
}, [url]);

return {
io: ioRef.current,
connected,
 };
 }


Solution 1:[1]

Are you using any framework to handle the websocket? Java can't do this natively, it doesn't know what the ws:// protocol is.

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 Hayden Taylor