-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTDMulticast.h
More file actions
144 lines (100 loc) · 3.39 KB
/
TDMulticast.h
File metadata and controls
144 lines (100 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//
// TDMulticast.h
// toocastkit
//
// Created by Daniele Poggi on 1/7/12.
// Copyright (c) 2012 Toodev. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "TDMulticastConfig.h"
#import "TCPServer.h"
#define kMaxInputDataBuffer 2048 // 2 KB
// Define the various tags we'll use to differentiate what it is we're currently reading or writing
#define TAG_READ_START 100
#define TAG_READ_STREAM 101
#define TAG_WRITE_START 200
#define TAG_WRITE_STREAM 201
#define TAG_WRITE_RECEIPT 202
// NOTIFICATION CENTER NAMES
#define kTDMulticastDiscoverServicesFinished @"kTDMulticastDiscoverServicesFinished"
// Will send element
#define kTDMulticastWillSendElement @"kTDMulticastWillSendElement"
// Did send element
#define kTDMulticastDidSendElement @"kTDMulticastDidSendElement"
// Did receive element
#define kTDMulticastDidReceiveElement @"kTDMulticastDidReceiveElement"
@interface TDMulticast : NSObject <TCPServerDelegate, NSNetServiceBrowserDelegate, NSNetServiceDelegate, NSStreamDelegate> {
// ANNOUNCE
TCPServer *_server;
//DISCOVER
NSString *_ownName;
NSNetService *_ownEntry;
/**
* @brief the array of discovered services
*/
NSMutableArray *_services;
/**
* @brief browser for net services
*/
NSNetServiceBrowser *_netServiceBrowser;
/**
* @brief current discovered net service
*/
NSNetService *_currentResolve;
// SEND
dispatch_queue_t outputStreamQueue;
/**
* @brief collection of input streams. the key of the dictionary is the name of the service
* the value is then the associated input stream
*/
NSMutableDictionary *inputStreams;
/**
* @brief collection of output streams. the key of the dictionary is the name of the service
* the value is then the associated output stream
*/
NSMutableDictionary *outputStreams;
/**
* @brief collection of outgoing queues. the key is the name of the peer name, the value
* is the mutable array of packets to send on the stream.
*/
NSMutableDictionary *outgoingQueues;
}
@property (nonatomic, readonly) NSMutableArray *services;
#pragma mark Kit Entry Point
/**
* @brief SINGLETON GETTER
*
* @return the shared instance of TDMulticast
*/
+ (TDMulticast*) sharedInstance;
#pragma mark - Utilities
#pragma mark - Announce/Conceal
/**
* @brief Announce the app on the LAN with the device name
*/
- (void) announce;
/**
* @brief Announce the app on the LAN with a specific name
*
* @param shownName the name that will be seen by others
*/
- (void) announceWithName:(NSString*)shownName;
- (void) announceWithName:(NSString *)shownName port:(NSUInteger)port;
#pragma mark Conceal
- (void) conceal;
- (void) concealWithName:(NSString*)shownName;
#pragma mark Discover
- (BOOL) discoverServices;
/**
* @brief discover TDMulticast Announced servers on the LAN
*/
- (BOOL) discoverServicesWithIdentifier:(NSString*)identifier inDomain:(NSString *)domain;
#pragma mark - Connect/Disconnect
- (void) connectWithService:(NSNetService*)service;
#pragma mark - Send/Receive
#pragma mark Send
- (void) sendDictionary:(NSDictionary*)dict;
#pragma mark Receive
/* Use Notification Center, register kTDMulticastReceive*** signature family */
- (void) didReceiveElement:(NSDictionary*)element fromPeer:(NSString*)peerName;
@end