Skip to content

Commit f78cf25

Browse files
authored
Merge pull request #55 from Borealis-Solutions/tcp-server-listening
OSCTCPServer isStarted
2 parents b38d942 + f3178a0 commit f78cf25

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

Sources/OSCKit/TCP/Server/OSCTCPServer.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ public final class OSCTCPServer {
4545
/// Network interface to restrict connections to.
4646
public let interface: String?
4747

48+
/// Returns a boolean indicating whether the OSC server has been started.
49+
public private(set) var isStarted: Bool = false
50+
4851
/// Initialize with a remote hostname and UDP port.
4952
///
5053
/// > Note:
@@ -94,10 +97,14 @@ extension OSCTCPServer: @unchecked Sendable { } // TODO: unchecked
9497
extension OSCTCPServer {
9598
/// Starts listening for inbound connections.
9699
public func start() throws {
100+
guard !isStarted else { return }
101+
97102
try tcpSocket.accept(
98103
onInterface: interface,
99104
port: _localPort ?? 0 // 0 causes system to assign random open port
100105
)
106+
107+
isStarted = true
101108
}
102109

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

108115
// close server
109116
tcpSocket.disconnectAfterWriting()
117+
118+
isStarted = false
110119
}
111120
}
112121

0 commit comments

Comments
 (0)