RuleGo RuleGo
🏠Home
  • Quick Start
  • Rule Chain
  • Standard Components
  • Extension Components
  • Custom Components
  • Visualization
  • RuleGo-Server
  • RuleGo-MCP-Server
  • AOP
  • Trigger
  • Advanced Topics
  • Performance
  • Standard Components
  • Extension Components
  • Custom Components
  • Components Marketplace
  • Overview
  • Quick Start
  • Routing
  • DSL
  • API
  • Options
  • Components
🔥Editor (opens new window)
  • RuleGo Editor (opens new window)
  • RuleGo Server (opens new window)
  • Github (opens new window)
  • Gitee (opens new window)
  • Changelog (opens new window)
  • English
  • 简体中文
🏠Home
  • Quick Start
  • Rule Chain
  • Standard Components
  • Extension Components
  • Custom Components
  • Visualization
  • RuleGo-Server
  • RuleGo-MCP-Server
  • AOP
  • Trigger
  • Advanced Topics
  • Performance
  • Standard Components
  • Extension Components
  • Custom Components
  • Components Marketplace
  • Overview
  • Quick Start
  • Routing
  • DSL
  • API
  • Options
  • Components
🔥Editor (opens new window)
  • RuleGo Editor (opens new window)
  • RuleGo Server (opens new window)
  • Github (opens new window)
  • Gitee (opens new window)
  • Changelog (opens new window)
  • English
  • 简体中文

广告采用随机轮播方式显示 ❤️成为赞助商
  • Quick Start

  • Rule Chain

  • Standard Components

  • Extension Components

  • Custom Components

  • Components marketplace

  • Visualization

  • AOP

  • Trigger

  • Advanced Topic

  • RuleGo-Server

  • FAQ

  • Endpoint Module

    • Endpoint Overview
    • Quick Start
    • Router
    • DSL
    • API
    • Options
    • Endpoints

      • Rest Endpoint
      • Websocket Endpoint
      • MQTT Endpoint
      • Schedule Endpoint
      • Net Endpoint
        • Type
        • Core Features
          • 🌐 Multi-Protocol Support
          • 📦 Smart Packet Splitting
          • 🔄 Data Type Processing
          • ⚡ Hot Reload Support
        • Configuration
        • Packet Splitting Modes
          • Line Mode (Default)
          • Fixed Mode
          • Delimiter Mode
          • Length Prefix Mode
        • Router Configuration
          • Recommended Configuration (Single Router Mode)
          • Advanced Router Configuration
        • Complete Configuration Examples
          • IoT Sensor Gateway
          • JSON API Server
          • UDP Broadcast Receiver
        • Hot Reload Example
        • Use Cases
          • 🏭 Industrial IoT
          • 🌐 Network Services
          • 📡 Device Connectivity
        • Best Practices
        • Example Code
      • Kafka Endpoint
      • Nats Endpoint
      • Redis Sub Endpoint
      • Redis Stream Endpoint
      • Rabbitmq Endpoint
      • MYSQL CDC Endpoint
      • OPC_UA Endpoint
      • gRPC Stream Endpoint
      • Beanstalkd Endpoint
      • Wukongim Endpoint
      • Extend Endpoint
  • Support

目录

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()
1
2
3
4

Available Processors:

  • setJsonDataType: For JSON APIs and REST services
  • setTextDataType: 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"
}
1
2
3

Suitable for text protocols, splits by \n or \r\n.

# Fixed Mode

{
  "packetMode": "fixed",
  "packetSize": 16
}
1
2
3
4

Fixed-length packets, suitable for binary protocols.

# Delimiter Mode

{
  "packetMode": "delimiter",
  "delimiter": "0x0D0A"
}
1
2
3
4

Custom delimiter, supports hex format.

# Length Prefix Mode

{
  "packetMode": "length_prefix_be",
  "packetSize": 2,
  "maxPacketSize": 4096
}
1
2
3
4
5

Length-prefix protocols, supports:

  • length_prefix_le: Little endian, length excludes prefix
  • length_prefix_be: Big endian, length excludes prefix
  • length_prefix_le_inc: Little endian, length includes prefix
  • length_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)
1
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)
1
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"
      }
    }
  ]
}
1
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"
      }
    }
  ]
}
1
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"
      }
    }
  ]
}
1
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))
1
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

  1. Data Type Selection

    • IoT sensors: Keep BINARY type for data integrity
    • JSON APIs: Use setJsonDataType processor
    • Text protocols: Use setTextDataType processor
  2. Router Design

    • Recommend single default router, handle complex logic in rule chains
    • Avoid excessive regex routes
  3. Performance Optimization

    • Set appropriate maxPacketSize to prevent malicious attacks
    • Configure proper readTimeout to avoid connection hogging
  4. Security Considerations

    • Limit server binding address in production environments
    • Use firewall to restrict access sources

# Example Code

Complete examples:

  • Net Endpoint Basic Usage (opens new window)
  • Fixed-Length Protocol Processing (opens new window)
  • Hot Reload Demonstration (opens new window)
Edit this page on GitHub (opens new window)
Last Updated: 2025/07/01, 10:33:52
Schedule Endpoint
Kafka Endpoint

← Schedule Endpoint Kafka Endpoint→

Theme by Vdoing | Copyright © 2023-2025 RuleGo Team | Apache 2.0 License

  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式