Acknowledgements
Request-response pattern over WebSocket. Send a message and receive a confirmation callback with automatic timeout.
Client → Server
// Client sends with callback
client.send(
{ type: "save-profile", payload: { name: "Alex" } },
(err, response) => {
if (err) {
console.error("Save failed or timed out:", err.message);
} else {
console.log("Profile saved:", response);
}
}
);Server responds
// Inside namespace connection handler
nsSocket.on("save-profile", (msg) => {
const ackId = (msg as any).__ackId;
if (ackId) {
// Process and send ack response
saveToDb(msg.payload);
nsSocket.sendAck(ackId, { success: true, id: 123 });
}
});Timeout
Acks time out after 10 seconds by default. Configure via ackTimeout in client options:
const client = new PPClient({
url: "ws://localhost:3000",
ackTimeout: 5000, // 5 seconds
});