Upload the file to Node.js server using Socket.io-stream from iOS

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) {
      //...I can't get a 'stream' to this event for it to work with
    });
    socket.on('passwordLogin', function (data, callback) {
      //...I can cause these kind of events just fine
    });
    //...other event declarations
 }

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:

//TODO: Attempt to expand SocketIO to include streams.
- (void) sendEvent:(NSString *)eventName withStream:(NSStream*) stream withData:(id) data   andAcknowledge:(SocketIOCallback) function
{
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObject:eventName forKey:@"name"];

    // do not require arguments
    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];
    //Is this even a valid approach?
    packet.stream = stream;//<--NEW BIT
    if (function) {
       packet.ack = @"data";
    }
    [self send:packet];
}

, , . Apple NSStream CFStream, , , . , .

+3

All Articles