Cloudfare web socket issue

What is the name of the domain?

What is the issue you’re encountering

I have been developing chat api using Cloudflare websocket. I could connect successfully with websocket. but the issue is it takes much time to respond the query, (less time for greeting messages and more time for acutal queries)

What steps have you taken to resolve the issue?

I have changed my ws.on like this
ws.on(“message”, (message) => {
try {
const parsed = JSON.parse(message.toString());

        // Print everything for debugging if needed
        // console.log("🔹 Raw message received:", JSON.stringify(parsed, null, 2));

        if (parsed.type === "universal.stream") {
            if (parsed.response?.content) {
                process.stdout.write(parsed.response.content);
            }
        } else if (parsed.type === "universal.complete") {
            isWaitingForResponse = false;
            console.log("\nYou: ");
        } else if (parsed.type === "universal.created") {
            // ✅ Handle and print non-streamed responses
            if (parsed.response?.result?.response) {
                console.log("\n" + parsed.response.result.response);
            } else {
                console.log("\n[No content in result.response]");
            }
            isWaitingForResponse = false;
            process.stdout.write("\nYou: ");
        } else {
            console.log("\n[System]", JSON.stringify(parsed, null, 2));
            isWaitingForResponse = false;
            process.stdout.write("\nYou: ");
        }
    } catch (err) {
        console.error("⚠️ Failed to parse message:", message.toString());
    }
});

Might be you’d need to implement a way to keep the socket connection alive for a longer period of a time? :thinking:

This topic was automatically closed after 15 days. New replies are no longer allowed.