Skip to content

RFA: add ping function to respond to JSON-RPC pings - #2298

Closed
sourdusk wants to merge 2 commits into
bitburner-official:devfrom
sourdusk:dev
Closed

RFA: add ping function to respond to JSON-RPC pings#2298
sourdusk wants to merge 2 commits into
bitburner-official:devfrom
sourdusk:dev

Conversation

@sourdusk

Copy link
Copy Markdown

PR includes no ns API changes but the documentation for RFA methods has been updated as part of this pull request.

npm run format and npm run lint have been run.

Has been tested both with a server with and without ping functionality and works fine.

Corresponds to bitburner-official/bitburner-filesync#35

},

ping: function (msg: RFAMessage): RFAMessage {
return new RFAMessage({ result: {}, id: msg.id });

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return new RFAMessage({ result: {}, id: msg.id });
return new RFAMessage({ result: null, id: msg.id });

I think null makes more sense for an empty response? And it also makes for a more straightforward type in ResultType.

@catloversg

Copy link
Copy Markdown
Collaborator

Why do we need this API? RFA is built on top of WebSocket, and ping-pong is defined in the protocol. All (good) libraries support it.

If the RFA tool wants to maintain the connection via a heartbeat, it should use the built-in ping-pong mechanic of WebSocket.

@d0sboots

Copy link
Copy Markdown
Collaborator

Ah, I didn't realize we could already accomplish this at a lower protocol layer.

@sourdusk

Copy link
Copy Markdown
Author

We're not currently using a websocket library in the code. Is that something that we want to adopt? Because otherwise, there's no way to send a ping websocket frame via the native javascript WebSocket API.

@catloversg

Copy link
Copy Markdown
Collaborator

We don't need to use any library on the game side. When the RFA tool sends ping, the WebSocket connection will automatically reply with pong as the RFC defines.

Test code (as RFA tool):

import { WebSocketServer } from "ws";

const wss = new WebSocketServer({ port: 12525 });

wss.on("connection", function connection(ws) {
  console.log("new connection");
  ws.on("error", console.error);
  ws.on("pong", function () {
    console.log("receive pong");
  });
});

setInterval(function ping() {
  for (const ws of wss.clients) {
    console.log("send ping");
    ws.ping();
  }
}, 5000);

How to test:

  • Run test code.
  • Set Bitburner's Remote API options and press Connect.
Capture

@sourdusk

Copy link
Copy Markdown
Author

I've added the websocket ping functionality as a pull request at bitburner-official/bitburner-filesync#36 . Closing this request.

@sourdusk sourdusk closed this Aug 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants