@@ -9,6 +9,7 @@ protocol SocketControllerViewDelegate: class {
9
9
enum SocketControllerState {
10
10
case waitingForHost
11
11
case readyToReceive
12
+ case error( message: String )
12
13
}
13
14
14
15
class SocketController : NSObject , StreamDelegate , GCDAsyncUdpSocketDelegate {
@@ -25,14 +26,24 @@ class SocketController: NSObject, StreamDelegate, GCDAsyncUdpSocketDelegate {
25
26
broadCastListnerSocket = GCDAsyncUdpSocket ( delegate: self , delegateQueue: DispatchQueue . main)
26
27
}
27
28
29
+
30
+ func closeSockets( ) {
31
+ outputSocket? . close ( )
32
+ broadCastListnerSocket? . close ( )
33
+ }
34
+
35
+ func openSockets( ) {
36
+ setupAutoDiscoveryListner ( ) ;
37
+ }
38
+
28
39
func setupAutoDiscoveryListner( ) {
29
40
30
41
do {
31
42
try broadCastListnerSocket? . bind ( toPort: 49452 )
32
43
try broadCastListnerSocket? . beginReceiving ( )
33
44
34
45
} catch {
35
- NotificationBanner ( title : " Uhh Oh! " , subtitle : " There was a problem enabling Auto Discovery " , style : . danger ) . show ( )
46
+ self . delegate ? . updatedState ( state : . error ( message : " There was a problem enabling Auto Discovery " ) )
36
47
print ( error)
37
48
}
38
49
@@ -47,15 +58,6 @@ class SocketController: NSObject, StreamDelegate, GCDAsyncUdpSocketDelegate {
47
58
let data = message. data ( using: . ascii) !
48
59
outputSocket? . send ( data, toHost: hostAddress!, port: 49452 , withTimeout: 0.1 , tag: 0 )
49
60
}
50
-
51
- func closeSockets( ) {
52
- outputSocket? . close ( )
53
- broadCastListnerSocket? . close ( )
54
- }
55
-
56
- func openSockets( ) {
57
- setupAutoDiscoveryListner ( ) ;
58
- }
59
61
60
62
func udpSocket( _ sock: GCDAsyncUdpSocket , didReceive data: Data , fromAddress address: Data , withFilterContext filterContext: Any ? ) {
61
63
let message = String ( data: data, encoding: String . Encoding. ascii)
0 commit comments