I am writing a native iOS client to interact with the Node.js server using the Socket.IO-objc shell . Currently, I can send individual events to the server. However, the server uses Socket.IO-stream to handle streams of downloaded files, and I need to somehow change the iOS code. My socket.io shell does not seem to have a corresponding API for this. The host .js server code is as follows:
io.sockets.on('connection', function (socket) {
console.log("connection occurring");
ss(socket).on('uploadFile', function (stream, data, callback) {
});
socket.on('passwordLogin', function (data, callback) {
});
}
I usually fire events this way and it works fine for socket.on events declared:
[_socket sendEvent:@"passwordLogin"
withData:@{...login info...}
andAcknowledge:aCallbackBlock];
I suppose I need to extend Socket.IO-objc if there isnβt something that I donβt see, with something like:
- (void) sendEvent:(NSString *)eventName withStream:(NSStream*) stream withData:(id) data andAcknowledge:(SocketIOCallback) function
{
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObject:eventName forKey:@"name"];
if (data != nil) {
[dict setObject:[NSArray arrayWithObject:data] forKey:@"args"];
}
SocketIOPacket *packet = [[SocketIOPacket alloc] initWithType:@"event"];
packet.data = [SocketIOJSONSerialization JSONStringFromObject:dict error:nil];
packet.pId = [self addAcknowledge:function];
packet.stream = stream;
if (function) {
packet.ack = @"data";
}
[self send:packet];
}
, , . Apple NSStream CFStream, , , . , .