RPC (Remote Procedure Calls)
-
RPC is a protocol that allows a program to execute functions on another computer or remote server as if it were calling a local function. It abstracts the complexity of network communication, making it appear as though the program is calling an internal function, when in fact the function resides on another system.
gRPC (Google RPC)
-
Uses Protobuf (Protocol Buffers) for data serialization and HTTP/2 for transport.
-
Structure :
-
Each gRPC message starts with a 5-byte length field.
-
The first byte is used to store a flag, while the next 4 bytes represent the total message size.
-
-
HTTP/2 divides communication into frames.
-
Each frame carries a payload size, and the frames are used to transport the actual message, being reassembled at the destination to reconstruct the original message.
-
-
-
Widely used in distributed systems and microservices.
JSON-RPC
-
An RPC protocol that uses the JSON format for requests and responses, generally used for web systems.
XML-RPC
-
Similar to JSON-RPC but uses XML to structure requests and responses.
HTTP
WebSockets
-
WebSockets are a communication protocol that allows a bidirectional , real-time connection between a client (usually a browser) and a server.
-
If these two features are not needed, HTTP may be better due to its simplicity.
-
-
Unlike HTTP, which is based on a request/response model (the client makes a request and the server responds), the WebSocket maintains an open and persistent connection between client and server, allowing both to send and receive data at any time.
-
It is based on signals/events.
-
-
It still uses a TCP connection, which is good for reliability but not for latency, so it is not ideal for real-time applications like VoIP and fast-paced games.
Usage Examples
-
Real-time chats.
-
Multiplayer games.
-
Financial trading applications.
Address (URI)
-
ws://(Unsecured WebSocket):-
The standard, unencrypted WebSocket protocol.
-
Used for communication on local networks or when security is not a priority, such as in development environments or internal networks.
-
Works similarly to
http://, without encryption or a security layer.
-
-
wss://(Secure WebSocket):-
The secure version of WebSocket, where communication is encrypted using TLS (Transport Layer Security), the same security mechanism used by
https://. -
Used when security is important, such as in production environments where sensitive data is transmitted.
-
Ensures that communication is protected against interception and attacks (such as man-in-the-middle attacks).
-
Explanations
-
-
WebSockets are discussed only at the end of the video. Most of the video criticizes the HTTP method.
-
In Godot
-
Using WebSockets to Turn an Android into a Controller .
-
The example basically follows Godot's documentation.
-
Two different projects are used, one to run the game and another to control the game from Android.
-
On Android, the App acts as a controller for the game running on the PC.
-
The Android device uses the accelerometer to control a ship on the PC.
-
Communication is done via sending and receiving packets, without
@rpc.
-
In Python
Requirements
-
pip install websockets. -
Use of 'asyncio'.
Example
import asyncio
import websockets
async def echo(websocket, path):
async for message in websocket:
print(f"Received message: {message}")
# Echo the message back to the client
await websocket.send(f"Echo: {message}")
start_server = websockets.serve(echo, "0.0.0.0", <port>)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()
-
About asynchrony:
-
asynciois Python's standard library for asynchronous programming. -
Using asynchronous functions is essential for creating responsive, efficient, and scalable applications, especially in environments where I/O and network communication are common. They allow cleaner, easier-to-maintain code and optimize system resource usage. If you are developing an application involving operations that may take time, using asynchronous functions is a good practice.
-
FTP (File Transfer Protocol)
-
Communication protocol used to transfer files between a client and a server over a network.
-
Not secure by default (uses plaintext), but can be combined with SSL/TLS (FTPS) to add security.