Coding Concepts 2
Coding Concepts 2
### 4. **Communication**:
- **TCP Socket**: Provides a reliable, ordered, and error-checked stream of bytes. The data is sent in a continuous stream and is delivered in
the same order as it was sent.
- **WebSocket**: Also provides a reliable, ordered communication stream but in the form of messages rather than raw byte streams.
WebSocket supports both text and binary messages.
### 5. **Performance**:
- **TCP Socket**: Since it is lower-level, TCP sockets might offer better performance for specialized applications where developers have fine-
grained control over how data is transmitted.
- **WebSocket**: Designed for ease of use in web applications, it abstracts some complexities, which might introduce minor overhead but is
more than adequate for most web-based real-time applications.
### 7. **Statefulness**:
- **TCP Socket**: Stateful by nature, meaning the connection between the client and server is maintained throughout the communication
session.
- **WebSocket**: Also stateful, maintaining an open connection for continuous communication until explicitly closed by either the client or
server.
### 8. **Security**:
- **TCP Socket**: Security features (like TLS/SSL) need to be manually implemented if required.
- **WebSocket**: Can be used over secure HTTPS (WSS: WebSocket Secure), which provides encryption and security out of the box, similar to
how HTTPS works.
### Summary:
- **TCP sockets** are fundamental building blocks for network communication, providing reliable, low-level, stream-oriented data transfer.
- **WebSockets** are a higher-level protocol designed for web applications, offering full-duplex communication suitable for real-time interaction
with web servers.
Each has its place, depending on the needs of the application being developed.