Всем привет! Не могу понять, у меня проблема или с сервером что-то не так?
// --- 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");
}