V
V
Vladislav Pavlenko2016-03-18 13:32:34
Objective-C
Vladislav Pavlenko, 2016-03-18 13:32:34

There is no response from the server. Where did I go wrong (PocketSocket)?

Hello! I can not understand, I have a problem or something is wrong with the server?

// --- Connect to the service ---
    // create the NSURLRequest that will be sent as the handshake
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"url"]];
    
    // create the socket and assign delegate
    self.socket = [PSWebSocket clientSocketWithRequest:request];
    self.socket.delegate = self;

    // open socket
    [self.socket open];

#pragma mark - PSWebSocketDelegate

- (void)webSocketDidOpen:(PSWebSocket *)webSocket
{
    NSLog(@"The websocket handshake completed and is now open!");
    NSDictionary *send = @{@"данные"};
    
    [webSocket send:[NSJSONSerialization dataWithJSONObject:send
                                                    options:kNilOptions
                                                      error:nil]];
}

- (void)webSocket:(PSWebSocket *)webSocket didReceiveMessage:(id)message
{
    NSString *string = [[NSString alloc] initWithData:message
                                             encoding:NSUTF8StringEncoding];
    NSLog(@"The websocket received a message: %@", string);
}

- (void)webSocket:(PSWebSocket *)webSocket didFailWithError:(NSError *)error
{
    NSLog(@"The websocket handshake/connection failed with an error: %@", error);
}

- (void)webSocket:(PSWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean
{
    NSLog(@"The websocket closed with code: %@, reason: %@, wasClean: %@", @(code), reason, (wasClean) ? @"YES" : @"NO");
}

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
G
German Polyansky, 2016-03-23
@pavlenkovs

uh, where's the description? Describe in detail what kind of response from the socket there is in general, what methods it enters, what it writes, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question