My task: to read every 'tick' of new information sent from the server socket, I will not send any data to the server.
Using the Socket.IO library, I try to connect to wss (websocket server), I have practically no experience in this process, so I’m not sure what information from the browser inspector I have to bring to my code.
Below is all the information that I got from Chrome Inspector (f12) -> Network -> WS -> headers , this information should be more than enough to successfully join the WSS.
General
Request URL: wss://tradeit.gg/socket.io/?EIO=3&transport=websocket&sid=jDTknMoBYlV7VOR3AWOj Request Method: GET Status Code: 101 Switching Protocols Response headers
CF-RAY: 44824ea40aaf8b58-KBP Connection: upgrade Date: Fri, 10 Aug 2018 12:01:20 GMT Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" Sec-WebSocket-Accept: xToN6aWToIogTQo3cOFKZpn6a44= Sec-WebSocket-Extensions: permessage-deflate; client_no_context_takeover Sec-WebSocket-Version: 13 Server: cloudflare Upgrade: websocket WebSocket-Server: uWebSockets Request headers
Accept-Encoding: gzip, deflate, br Accept-Language: ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7 Cache-Control: no-cache Connection: Upgrade Cookie: __cfduid=d4f3e1f3363b2ffcec6209cae50f95df91530538054; _ga=GA1.2.642241760.1530538057; _gid=GA1.2.1752480950.1533821233; smaller_icons=true; io=jDTknMoBYlV7VOR3AWOj Host: tradeit.gg Origin: https://tradeit.gg Pragma: no-cache Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits Sec-WebSocket-Key: pMGG6zJSm8CF97iHAvyWrw== Sec-WebSocket-Version: 13 Upgrade: websocket User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36 Query string parameters
EIO: 3 transport: websocket sid: jDTknMoBYlV7VOR3AWOj I am sure that I provided more than 80% of unnecessary information, but this is because I don’t know which one might be useful. Code:
Socket socket = IO.socket(""); socket.on(Manager.EVENT_TRANSPORT, new Emitter.Listener() { public void call(Object... objects) { Transport transport = null; transport.on(Transport.EVENT_REQUEST_HEADERS, new Emitter.Listener() { public void call(Object... objects) { Map<String, List<String>> headers = new HashMap<String, List<String>>(); headers.put("Cookie", Arrays.asList("tokenName1=tokenValue1", "tokenNameN=tokenValueN")); } }); transport.on(Transport.EVENT_RESPONSE_HEADERS, new Emitter.Listener() { public void call(Object... objects) { Map<String, List<String>> headers = new HashMap<String, List<String>>(); String cookie = headers.get("Set-Cookie").get(0); System.out.println(cookie); } }); } }); Actually questions:
1. What line to add to IO.Socket to initialize the socket object?
2. How to initialize the transport object?
3. What headings should I add for a successful connection.
4. How to receive data sent from the server web socket.
I have already dealt with the Pusher library in Java, but in this case I also don’t understand how to get the necessary data (hostname, wssport, key , etc ...).
javax.websocket? - ArchDemon