You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
WebSocket connections in Clearnode provide real-time, bidirectional communication between clients and the server. These persistent connections enable immediate message delivery, automatic balance updates, and efficient RPC communication. However, like all network connections, WebSocket connections can occasionally drop due to network issues, timeouts, or server-side constraints.
❓ Why do WebSocket connections drop?
WebSocket connections can drop for several reasons:
Write timeouts: If the server cannot send a message to the client within 5 seconds (the default defaultRPCMessageWriteDuration), the connection will be automatically closed to prevent resource exhaustion
Network interruptions: Temporary network issues, proxy timeouts, or ISP problems
Client inactivity: Extended periods without any communication may trigger connection cleanup
Server maintenance: Planned or unplanned server restarts and deployments
When a connection drops due to a write timeout, you'll typically see an error message like:
"websocket: close 1006 (abnormal closure): unexpected EOF"
❓ How should I handle dropping connections?
There are two main strategies for dealing with connection drops:
Option 1: Continuous Pinging
Implement regular calls that invoke the Clearnode's ping endpoint to keep the connection alive and detect drops early:
// Send ping every 30 secondsconstpingInterval=setInterval(()=>{if(websocket.readyState===WebSocket.OPEN){// Send ping using the Clearnode ping methodconstpingMessage={"req": [Date.now(),"ping",{},Date.now()],"sig": ["your_signature"]};websocket.send(JSON.stringify(pingMessage));}},30000);
Benefits:
Maintains persistent connection
Immediate message delivery
Real-time balance and channel updates
Lower latency for frequent operations
Option 2: Connect on Demand
Establish connections only when needed and authenticate fresh each time:
asyncfunctionconnectAndAuth(){constws=newWebSocket('wss://clearnet.yellow.com/ws');// Perform full authentication flowawaitauthenticate(ws);// Use connection for your operationawaitperformOperation(ws);// Close when donews.close();}
Benefits:
Reduced resource usage
No connection maintenance overhead
Always fresh authentication state
Suitable for infrequent operations
Recommendation: Use continuous pinging for applications requiring real-time updates (trading bots, games), and connect on demand for occasional operations (simple transfers, balance checks).
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Clearnode WebSocket Connection
WebSocket connections in Clearnode provide real-time, bidirectional communication between clients and the server. These persistent connections enable immediate message delivery, automatic balance updates, and efficient RPC communication. However, like all network connections, WebSocket connections can occasionally drop due to network issues, timeouts, or server-side constraints.
❓ Why do WebSocket connections drop?
WebSocket connections can drop for several reasons:
defaultRPCMessageWriteDuration
), the connection will be automatically closed to prevent resource exhaustionWhen a connection drops due to a write timeout, you'll typically see an error message like:
"websocket: close 1006 (abnormal closure): unexpected EOF"
❓ How should I handle dropping connections?
There are two main strategies for dealing with connection drops:
Option 1: Continuous Pinging
Implement regular calls that invoke the Clearnode's
ping
endpoint to keep the connection alive and detect drops early:Benefits:
Option 2: Connect on Demand
Establish connections only when needed and authenticate fresh each time:
Benefits:
Recommendation: Use continuous pinging for applications requiring real-time updates (trading bots, games), and connect on demand for occasional operations (simple transfers, balance checks).
Beta Was this translation helpful? Give feedback.
All reactions