@@ -10,39 +10,39 @@ import Foundation
10
10
import Network
11
11
12
12
public class OSCClient {
13
-
13
+
14
14
var connection : NWConnection ?
15
15
var queue : DispatchQueue
16
-
17
- var host : NWEndpoint . Host
16
+
17
+ public var host : NWEndpoint . Host
18
18
public var port : NWEndpoint . Port
19
-
19
+
20
20
public init ? ( host: String , port: Int ) {
21
-
21
+
22
22
// check if string is empty
23
23
if host == " " {
24
-
24
+
25
25
NSLog ( " Invalid Hostname: No empty strings allowed. " )
26
26
return nil
27
-
27
+
28
28
}
29
29
if port > 65535 && port >= 0 {
30
30
NSLog ( " Invalid Port: Out of range. " )
31
31
return nil
32
32
}
33
-
33
+
34
34
self . host = NWEndpoint . Host ( host)
35
35
self . port = NWEndpoint . Port ( integerLiteral: UInt16 ( port) )
36
-
36
+
37
37
queue = DispatchQueue ( label: " SwiftOSC Client " )
38
38
setupConnection ( )
39
39
}
40
-
40
+
41
41
func setupConnection( ) {
42
-
42
+
43
43
// create the connection
44
44
connection = NWConnection ( host: host, port: port, using: . udp)
45
-
45
+
46
46
// setup state update handler
47
47
connection? . stateUpdateHandler = { [ weak self] ( newState) in
48
48
switch newState {
@@ -62,13 +62,13 @@ public class OSCClient {
62
62
break
63
63
}
64
64
}
65
-
65
+
66
66
// start the connection
67
67
connection? . start ( queue: queue)
68
68
}
69
-
69
+
70
70
public func send( _ element: OSCElement ) {
71
-
71
+
72
72
let data = element. oscData
73
73
connection? . send ( content: data, completion: . contentProcessed( { ( error) in
74
74
if let error = error {
@@ -80,7 +80,7 @@ public class OSCClient {
80
80
// destroy connection and listener
81
81
connection? . forceCancel ( )
82
82
83
-
83
+
84
84
// setup new listener
85
85
setupConnection ( )
86
86
}
0 commit comments