Extension: omni.sensors.net-1.0.1 |
Documentation Generated: Nov 13, 2025 |
Overview#
omni.sensors.net provides a channel-based networking framework for TCP/IP, Realm networking, and topic-based communication. The extension establishes a unified interface for creating network channels and servers that can handle different types of endpoints including IPv4, CAN, realm, and custom protocol endpoints.
Concepts#
Endpoints#
The networking framework uses endpoints to define communication destinations. An Endpoint represents a network destination with a specific type and timestamp, supporting multiple network protocols through EndpointType enumeration:
E_IP: IPv4 addresses using IP4EndpointE_CAN: CAN bus endpointsE_REALM: Realm-based network endpointsE_CUSTOM: Protocol-specific custom endpoints
Network Backend Architecture#
The extension follows a factory pattern where INetworkFactory creates channels and servers through registered INetworkBackend implementations. This allows the same API to work across different network protocols and transport layers.
Key Components#
Channel Interface#
IChannel provides the primary interface for bidirectional network communication. Channels support both broadcast and targeted sending through endpoint specification:
# Send to specific endpoint
channel.send(data_bytes, endpoint)
# Broadcast send
channel.send(data_bytes)
Reception handling uses consumer callbacks registered through add_reception_consumer(), where each IReceptionConsumer receives incoming data and sender endpoint information.
Server Interface#
IServer manages connection-based protocols like TCP and WebSocket servers. Servers use IConnectionConsumer callbacks to handle new client connections, automatically creating channels for each connected client.
Network Factory#
INetworkFactory serves as the entry point for creating network resources. Both channels and servers are instantiated through factory methods that accept configuration dictionaries, allowing backend-specific parameters to be passed through a common interface.
Usage Examples#
Creating a channel for network communication:
import omni.sensors.net as net
# Get factory instance
factory = net.INetworkFactory()
# Create channel with configuration
config = {"type": "tcp", "port": 8080}
channel = factory.make_channel(config)
# Register reception handler
def handle_data(data: bytes, endpoint: net.Endpoint):
print(f"Received {len(data)} bytes from {endpoint.type}")
consumer = channel.add_reception_consumer(handle_data)
Setting up a server for incoming connections:
# Create server
server_config = {"type": "tcp", "bind_port": 9090}
server = factory.make_server(server_config)
# Handle new connections
def on_client_connect(channel: net.IChannel, endpoint: net.Endpoint):
print(f"New client connected from {endpoint.ip.port}")
server.add_connection_consumer(on_client_connect)