MegaBits / SIOSocket

Realtime iOS application framework (client) http://socket.io
MIT License
493 stars 80 forks source link

SIOSocket connected but not emmmiting data #9

Closed andrew-frank closed 10 years ago

andrew-frank commented 10 years ago

Hello, I'm facing an issue. I follwed your example WorldPin and wrote the code below. I can see connection opened on the server, but no message is actually emmited. I don't get any errors etc. I am clueless. Thanks in advance for any help.

-(void)connectSocket:(NSString *)token
{
    NSString *hostURL = [NSString stringWithFormat:@"%@/%@?accessToken=%@", kPHServerBaseURL, @"socket.io", token];
    DLog(@"%@", hostURL);

    [SIOSocket socketWithHost:hostURL response:^(SIOSocket *socket) {

        self.socket = socket;

        __weak typeof(self) weakSelf = self;
        self.socket.onConnect = ^() {
            weakSelf.socketIsConnected = YES;
            DLog(@"CONNECTED");
            [weakSelf.socket emit:@"join", @{@"id": weakSelf.chatRoom.ID}, nil];
        };

        self.socket.onError = ^(NSDictionary *data)  {
            DLog(@"error: %@", data);
        };

        self.socket.onReconnectionAttempt = ^(NSInteger recCounter) {
            DLog(@"Reconnection counter %li", (long)recCounter);
        };

        self.socket.onReconnectionError = ^(NSDictionary *data) {
            DLog(@"reconnection error: %@", data);
        };

        [self.socket on:@"msg" do: ^(id data) {
             DLog(@"NEW MESSAGE! \n on: msg, %@", data);

             [JSQSystemSoundPlayer jsq_playMessageReceivedSound];
             [weakSelf receivedMessageData:data];
             [weakSelf finishReceivingMessage];             
         }];

        [self.socket on: @"notice" do: ^(id data) {
            DLog(@"NEW NOTICE!! %@", data);
        }];

    }];
}
- (void)didPressSendButton:(UIButton *)button withMessageText:(NSString *)text sender:(NSString *)sender date:(NSDate *)date
{    
    [JSQSystemSoundPlayer jsq_playMessageSentSound];

    AMChatMessage *message = [[AMChatMessage alloc] initWithText:text sender:sender date:date];

    if(self.socketIsConnected) {
        [self.messages addObject:message];
        [self.socket emit:@"msg", @{@"body": text, @"room": self.chatRoomModel.ID}, nil];
        DLog(@"MESSAGE SENT");
        [self finishSendingMessage];
    } else {
        DLog(@"NOT CONNECTED");
    }
}
andrew-frank commented 10 years ago

I solved this issue by converting dictionary to a string and sending parameters this way, although I'm getting the response of type NSDictionary.

PengsreangSrun commented 9 years ago

I have faced the problem that cannot connect to server. Can all of you guys help me?