-
-
Notifications
You must be signed in to change notification settings - Fork 24
Open
Description
Depending on how the server is used, it sometimes only needs to deal with specific connections. For example, disconnect a specific connection or send data to a specific connection(s).
In my case I was having the server manage sessions which clients could join/leave. So I added the following (very simple) code.
// MBWebSocketServer.h
- (void)disconnectConnection:(GCDAsyncSocket *)aConnection;
- (void)sendToConnection:(GCDAsyncSocket *)aConnection data:(id)object;
- (void)sendToConnections:(NSArray *)aCollectionsArray data:(id)object;
// MBWebSocketServer.m
- (void)sendToConnection:(GCDAsyncSocket *)aConnection data:(id)object {
NSData *payload = [object webSocketFrameData];
[aConnection writeData:payload withTimeout:-1 tag:3];
}
- (void)sendToConnections:(NSArray *)aCollectionsArray data:(id)object {
id payload = [object webSocketFrameData];
for (GCDAsyncSocket *connection in aCollectionsArray) {
[connection writeData:payload withTimeout:-1 tag:3];
}
}
- (void)disconnectConnection:(GCDAsyncSocket *)aConnection {
[aConnection disconnect];
}Metadata
Metadata
Assignees
Labels
No labels