crystal-sctp
Crystal SCTP
Crystal bindings and high-level API for libusrsctp, providing SCTP (Stream Control Transmission Protocol) support for macOS and Linux.
Features
- ๐ High-level Socket-like API for SCTP
- ๐ง Complete bindings to libusrsctp
- ๐ Multi-homing support (bind/connect to multiple addresses)
- ๐ฆ Multi-streaming support
- ๐ Type-safe Crystal interface
- ๐งช Comprehensive test suite
- ๐ macOS and Linux support
Installation
-
Install libusrsctp:
macOS:
brew install usrsctpLinux (Ubuntu/Debian):
sudo apt-get install libusrsctp-dev -
Add this to your application's
shard.yml:dependencies: sctp: github: yourusername/crystal-sctp -
Run
shards install
Usage
Basic Server
require "sctp"
# Create and bind an SCTP socket
server = SCTP::Socket.new
server.bind("127.0.0.1", 3000)
server.listen
puts "SCTP server listening on port 3000"
# Accept connections
loop do
client = server.accept
spawn do
message = client.read_string(1024)
puts "Received: #{message}"
client.write("Echo: #{message}")
client.close
end
end
Basic Client
require "sctp"
# Connect to SCTP server
client = SCTP::Socket.new
client.connect("127.0.0.1", 3000)
client.write("Hello, SCTP!")
response = client.read_string(1024)
puts "Server response: #{response}"
client.close
Multi-streaming
require "sctp"
socket = SCTP::Socket.new(streams: 10)
socket.connect("127.0.0.1", 3000)
# Send on different streams
socket.write("Stream 0 data", stream: 0)
socket.write("Stream 1 data", stream: 1)
socket.write("Stream 5 data", stream: 5)
socket.close
Multi-homing (Redundant Addresses)
require "sctp"
# Server binds to multiple addresses for redundancy
server = SCTP::Socket.new
server.bind(["192.168.1.100", "10.0.0.100"], 3000)
server.listen
# Client connects to multiple addresses
client = SCTP::Socket.new
client.connect(["192.168.1.100", "10.0.0.100"], 3000)
# SCTP automatically handles failover between addresses
client.write("Data with redundant paths")
client.close
API Overview
The library provides several classes:
SCTP::Socket- High-level socket interface (similar to TCPSocket/UDPSocket)SCTP::Server- High-level server interface (similar to TCPServer)SCTP::Address- Represents SCTP addresses with multi-homing supportSCTP::Stream- Represents individual SCTP streamsLibUsrSCTP- Low-level C bindings
Development
# Run tests
crystal spec
# Run examples
crystal run examples/server.cr
crystal run examples/client.cr
Contributing
- Fork it (https://github.com/yourusername/crystal-sctp/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
License
MIT License - see LICENSE file for details
Resources
Repository
crystal-sctp
Owner
Statistic
- 1
- 0
- 0
- 0
- 0
- 2 months ago
- December 27, 2025
License
MIT License
Links
Synced at
Tue, 27 Jan 2026 10:23:43 GMT
Languages