this is what all proper network clients do... you can see examples of it in the bitcoin core and btcd p2p code as well
front end devs are not often so well versed in the problems of socket networking, being used to HTTP APIs... websocket libraries don't give you any tools for this either