Choosing a Transport
Choosing the right transport method is crucial for optimal performance and compatibility in your application. Cobra Transports includes three options: TCP, UDP, and WebSocket. Each transport has its strengths and considerations, so let's explore them to help you make an informed decision.
UDP Transport
The UDP transport in Cobra Transports is the fastest option available. While raw UDP is typically unreliable and unordered, the included UDP transport ensures reliable and ordered data transmission. This means you have the flexibility to prioritize critical data over non-critical data, for example positions and rotations are likely non-critical and it's okay if some packets are lost, while other types of packets such as chat messages need to be sent reliably and they must arrive in same order as they were sent.
The UDP transport is an excellent choice for applications requiring high data send rates, such as FPS games. However, it's important to know that UDP sockets are not permitted in web browsers so the UDP transport cannot be used in WebGL applications.
Tcp Transport
The TCP transport always ensures reliable and ordered data transmission, making it a dependable choice for applications prioritizing data integrity over raw speed. While slightly heavier than UDP, TCP may be preferable when high data rates aren't critical or when targeting platforms that don't support UDP.
Websocket Transport
Designed with web-based applications in mind, the WebSocket transport is perfect for projects deployed in web browsers. It strikes a balance between reliability and compatibility, making it an excellent fit for WebGL builds.
One notable advantage is the option to encrypt data using a reverse proxy, enhancing security for your transmissions.