This article applies to:
- Ethereum
- Polygon
- BNB Smart Chain
- Avalanche
- Fantom
Difference between HTTP and WebSocket protocols
HTTP is unidirectional while WebSocket is bidirectional.
In client-server communication, each HTTP request from the client establishes a new connection and gets closed on receiving a response from the server.
In client-server communication, a WebSocket connection is made once and reused until either the server or the client terminates the connection. For proper usage of your websocket endpoint, please refer to this documentation.
HTTP vs WebSocket for EVM node connections
The general recommendation is to use WebSocket rather than HTTP when connecting to an EVM node. WebSocket has the advantage of the connection reusability and the keep-alive mechanism.
HTTP
- 60 seconds timeout for idle connection.
- Can be used for calls that have very short response time such as eth_call, eth_sendRawTransaction.
WebSocket
- 3600 seconds (1 hour) timeout for idle connection.
- Should be used for calls like eth_getLogs that have a response rate longer than 60 seconds.
- Maximum number of connections is 250.
To access Node and Connections limitations, please visit this document.
If you have any questions, feel free to contact Chainstack support by emailing support@chainstack.com or by submitting this form.
See also WebSocket connection to an EVM node.
Comments
0 comments
Please sign in to leave a comment.