Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Sources/OSCKit/TCP/Server/OSCTCPServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public final class OSCTCPServer {
/// Network interface to restrict connections to.
public let interface: String?

/// Returns a boolean indicating whether the OSC server has been started.
public private(set) var isStarted: Bool = false

/// Initialize with a remote hostname and UDP port.
///
/// > Note:
Expand Down Expand Up @@ -94,10 +97,14 @@ extension OSCTCPServer: @unchecked Sendable { } // TODO: unchecked
extension OSCTCPServer {
/// Starts listening for inbound connections.
public func start() throws {
guard !isStarted else { return }

try tcpSocket.accept(
onInterface: interface,
port: _localPort ?? 0 // 0 causes system to assign random open port
)

isStarted = true
}

/// Closes any open client connections and stops listening for inbound connection requests.
Expand All @@ -107,6 +114,8 @@ extension OSCTCPServer {

// close server
tcpSocket.disconnectAfterWriting()

isStarted = false
}
}

Expand Down
Loading