class

SCTP::Socket

Inherits IO < Reference < Object

High-level SCTP socket implementation

This class provides a Socket-like interface for SCTP communication, supporting features like multi-streaming, multi-homing, and ordered/unordered delivery.

Example:

socket = SCTP::Socket.new
socket.connect("127.0.0.1", 3000)
socket.write("Hello, SCTP!")
response = socket.read_string(1024)
socket.close

Constructors

new(streams : Int32 = 1, max_attempts : Int32 = 4)

Create a new SCTP socket

  • streams: Number of streams to negotiate (default: 1)
  • max_attempts: Maximum number of initialization attempts
Source

Instance methods

accept

Accept an incoming connection

Source
add_bind_address(host : String, port : Int32) : Void

Add an additional local address to the socket (for multi-homing)

Source
bind(host : String, port : Int32) : Void

Bind the socket to a local address

Source
bind(hosts : Array(String), port : Int32) : Void

Bind the socket to multiple local addresses (multi-homing)

Example:

socket.bind(["192.168.1.100", "10.0.0.100"], 3000)
Source
close

Close the socket

Source
closed?

Check if socket is closed

Source
connect(host : String, port : Int32) : Void

Connect to a remote SCTP server

Source
connect(hosts : Array(String), port : Int32) : Void

Connect to multiple remote addresses (multi-homing)

SCTP will use these addresses for redundancy and automatic failover.

Example:

socket.connect(["192.168.1.100", "10.0.0.100"], 3000)
Source
finalize
Source
inbound_streams

Number of inbound streams

Source
listen(backlog : Int32 = 128) : Void

Listen for incoming connections

Source
local_address

Get local address

Source
no_delay=(value : Bool)

Set SCTP_NODELAY option (disable Nagle)

Source
non_blocking=(value : Bool)

Set socket to non-blocking mode

Source
non_blocking?

Check if socket is non-blocking

Source
outbound_streams

Number of outbound streams

Source
read(slice : Bytes) : Int32

Read data from the socket

Source
read_string(max_size : Int32 = 4096) : String

Read a string from the socket

Source
read_with_info(slice : Bytes) : Tuple(Int32, UInt16, UInt32)

Read data with stream information

Source
remote_address

Get remote address

Source
remove_bind_address(host : String, port : Int32) : Void

Remove a local address from the socket

Source
write(slice : Bytes) : Nil

Write data to the socket

Source
write(data : String | Bytes, stream : Int32 = 0, unordered : Bool = false, ppid : UInt32 = 0_u32) : Nil

Write data to a specific stream

Source