On Tue, 04 Jun 2024 15:33:51 GMT, MrX wrote:
On Tue, 04 Jun 2024 08:58:05 GMT, Sönke Ludwig wrote:
On Tue, 28 May 2024 12:19:26 GMT, MrX wrote:
Hello,
Could someone share an example on how to execute a ping/pong through a WebSocket?
Thank you.
Since there a similar ticket just popped up, in case this is actually meant to send a low-level ping/pong on the web socket protocol level, this might be relevant: https://github.com/vibe-d/vibe.d/issues/2802
module app; import vibe.core.core; import vibe.core.log; import vibe.http.fileserver : serveStaticFiles; import vibe.http.router : URLRouter; import vibe.http.server; import vibe.web.web; import vibe.http.websockets; import vibe.vibe; int main(string[] args) { string WS_URL= "wss://echo.websocket.org"; auto ws_url = URL(WS_URL); const use_tls = (ws_url.schema == "wss" || ws_url.schema == "https") ? true : false; ws_url.schema = use_tls ? "https" : "http"; auto receiver = connectWebSocket(ws_url); ConnectionStream m_conn; RandomNumberStream m_rng; auto message = new OutgoingWebSocketMessage(m_conn, FrameOpcode.ping, m_rng); while (receiver.waitForData()) { auto msg = parseJsonString(receiver.receiveText()); try { ws.send((message) { message.write([]); }, FrameOpcode.ping); } catch (Exception ex) { logInfo("error %s", ex.msg); } logInfo("%s", msg); } return 0; }
This does not work:
source/app.d(30,17): Error: classvibe.http.websockets.OutgoingWebSocketMessage
constructorthis
is not accessible
source/app.d(39,32): Error: none of the overloads ofwrite
are callable using argument types()
Do you have an example that works?
Sorry receiver.send((message) { message.write([]); }, FrameOpcode.ping);
typo fix.