Net Endpoint
Net Endpoint creates and starts network protocol servers with support for multiple protocols and packet processing modes. Ideal for IoT device connectivity, sensor data collection, network protocol proxying, and real-time data processing.
# Type
endpoint/net
# Core Features
# 🌐 Multi-Protocol Support
- TCP/UDP: Standard network protocols
- IPv4/IPv6: Support for ip4:1, ip6:ipv6-icmp, ip6:58, etc.
- Unix Socket: unix, unixgram local communication
- Extended Protocols: All protocol types supported by Go's net package
# 📦 Smart Packet Splitting
- line: Split by newlines (\n or \r\n) - default mode
- fixed: Fixed-length splitting
- delimiter: Custom delimiter (supports hex format)
- length_prefix: Length-prefix mode (supports endianness, includes/excludes prefix length)
# 🔄 Data Type Processing
Default Behavior: All network data defaults to BINARY type to preserve data integrity.
Type Conversion: Change data type using built-in processors:
// Use processors in router configuration
router := impl.NewRouter().From("").
Process("setJsonDataType"). // Set to JSON type
To("chain:jsonProcessor").End()
2
3
4
Available Processors:
setJsonDataType
: For JSON APIs and REST servicessetTextDataType
: For text-based protocols (HTTP, SMTP, etc.)setBinaryDataType
: Explicitly set to binary (default)
# ⚡ Hot Reload Support
Supports rule chain hot reloading without server restart to update processing logic.
# Configuration
Field | Type | Required | Description | Default |
---|---|---|---|---|
protocol | string | No | Network protocol: tcp/udp/unix, etc. | tcp |
server | string | Yes | Server address in host:port format, e.g., ":8888" | - |
readTimeout | int | No | Read timeout in seconds, 0 for no timeout | 60 |
packetMode | string | No | Packet splitting mode | line |
packetSize | int | No | Packet size (meaning varies by mode) | 0 |
delimiter | string | No | Custom delimiter (supports 0x0A hex format) | - |
maxPacketSize | int | No | Maximum packet size to prevent malicious attacks | 64KB |
encode | string | No | ⚠️ Deprecated: hex/base64 encoding, use rule chains | - |
# Packet Splitting Modes
# Line Mode (Default)
{
"packetMode": "line"
}
2
3
Suitable for text protocols, splits by \n
or \r\n
.
# Fixed Mode
{
"packetMode": "fixed",
"packetSize": 16
}
2
3
4
Fixed-length packets, suitable for binary protocols.
# Delimiter Mode
{
"packetMode": "delimiter",
"delimiter": "0x0D0A"
}
2
3
4
Custom delimiter, supports hex format.
# Length Prefix Mode
{
"packetMode": "length_prefix_be",
"packetSize": 2,
"maxPacketSize": 4096
}
2
3
4
5
Length-prefix protocols, supports:
length_prefix_le
: Little endian, length excludes prefixlength_prefix_be
: Big endian, length excludes prefixlength_prefix_le_inc
: Little endian, length includes prefixlength_prefix_be_inc
: Big endian, length includes prefix
# Router Configuration
# Recommended Configuration (Single Router Mode)
// Simple configuration
router := impl.NewRouter().From("").To("chain:main").End()
ep.AddRouter(router)
// With data type processor
router := impl.NewRouter().From("").
Process("setJsonDataType").
To("chain:jsonProcessor").End()
ep.AddRouter(router)
2
3
4
5
6
7
8
9
# Advanced Router Configuration
// Router matching options
options := &net.RouterMatchOptions{
MatchRawData: true, // Match raw data
DataTypeFilter: "JSON", // Data type filter
MinDataLength: 10, // Minimum data length
MaxDataLength: 1024, // Maximum data length
}
router := impl.NewRouter().From("^sensor.*").To("chain:sensor").End()
routerId, err := ep.AddRouter(router, options)
2
3
4
5
6
7
8
9
# Complete Configuration Examples
# IoT Sensor Gateway
{
"id": "iot_gateway",
"type": "endpoint/net",
"configuration": {
"protocol": "tcp",
"server": ":8080",
"packetMode": "length_prefix_be",
"packetSize": 2,
"maxPacketSize": 1024,
"readTimeout": 30
},
"routers": [
{
"from": {
"path": ".*",
"processors": ["setBinaryDataType"]
},
"to": {
"path": "chain:iotProcessor"
}
}
]
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# JSON API Server
{
"id": "json_api",
"type": "endpoint/net",
"configuration": {
"protocol": "tcp",
"server": ":9090",
"packetMode": "line",
"readTimeout": 60
},
"routers": [
{
"from": {
"path": ".*",
"processors": ["setJsonDataType"]
},
"to": {
"path": "chain:apiProcessor"
}
}
]
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# UDP Broadcast Receiver
{
"id": "udp_receiver",
"type": "endpoint/net",
"configuration": {
"protocol": "udp",
"server": ":8888",
"maxPacketSize": 2048
},
"routers": [
{
"from": {
"path": ".*",
"processors": ["setTextDataType"]
},
"to": {
"path": "chain:udpProcessor"
}
}
]
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Hot Reload Example
// Initial DSL configuration
initialDSL := `{
"ruleChain": {
"id": "iotProcessor",
"root": true
},
"metadata": {
"endpoints": [...],
"nodes": [...]
}
}`
// Start rule engine
ruleEngine, _ := rulego.New("iotProcessor", []byte(initialDSL))
// Hot reload configuration
updatedDSL := `{...}` // New configuration
err := ruleEngine.ReloadSelf([]byte(updatedDSL))
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Use Cases
# 🏭 Industrial IoT
- Sensor data collection
- PLC device communication
- Modbus TCP proxy
# 🌐 Network Services
- TCP/UDP proxy
- Protocol conversion gateway
- Real-time data streaming
# 📡 Device Connectivity
- MQTT gateway
- Device registration service
- Heartbeat monitoring
# Best Practices
Data Type Selection
- IoT sensors: Keep BINARY type for data integrity
- JSON APIs: Use
setJsonDataType
processor - Text protocols: Use
setTextDataType
processor
Router Design
- Recommend single default router, handle complex logic in rule chains
- Avoid excessive regex routes
Performance Optimization
- Set appropriate
maxPacketSize
to prevent malicious attacks - Configure proper
readTimeout
to avoid connection hogging
- Set appropriate
Security Considerations
- Limit server binding address in production environments
- Use firewall to restrict access sources
# Example Code
Complete examples: