nuclearace / Socket.IO-Client-Swift

socket.io-client for Swift
Other
361 stars 53 forks source link

Objective-C : Cant connect to server using Socket.IO #167

Open harshanakaru opened 6 years ago

harshanakaru commented 6 years ago

Hi,

I'm using Socket.IO-Client-Swift' -13.2.0' to implement my project in Objective-C. I'm trying to connect to a Node.js service using Socket.IO and have followed the documentation for Objective-C. But when i try to run my code, the console logs 'tried connecting socket when engine isn't open' and cant get through.

Following is my code,

@import SocketIO;
NSURL* url = [[NSURL alloc] initWithString:@"http://URL_STRING:PORT_NUMBER"];

SocketManager *manager = [[SocketManager alloc] initWithSocketURL:url config:@{@"log":@yES, @"compress":@yES}];
SocketIOClient *socket = [manager defaultSocket];

[socket on:@"connect" callback:^(NSArray* data, SocketAckEmitter* ack) {
NSLog(@"socket connected");
}];

[socket connect];

And the console,


2018-06-01 00:22:06.694853+1000 [885:732318] LOG SocketIOClient{/}: Adding handler for event: connect
2018-06-01 00:22:06.695467+1000 [885:732318] LOG SocketIOClient{/}: Handling event: statusChange with data: [connecting]
2018-06-01 00:22:06.695578+1000 [885:732318] LOG SocketIOClient{/}: Joining namespace /
2018-06-01 00:22:06.695639+1000 [885:732318] LOG SocketManager: Tried connecting socket when engine isn't open. Connecting
2018-06-01 00:22:06.695679+1000 [885:732318] LOG SocketManager: Adding engine
2018-06-01 00:22:06.697262+1000 [885:732355] LOG SocketEngine: Starting engine. Server: http://URL_STRING:PORT_NUMBER
2018-06-01 00:22:06.697323+1000 [885:732355] LOG SocketEngine: Handshaking
2018-06-01 00:22:06.699886+1000 [885:732355] LOG SocketEnginePolling: Doing polling GET http://URL_STRING:PORT_NUMBER/socket.io/?transport=polling&b64=1

How to solve this issue? Thanks.

yongwumai commented 6 years ago

you have to keep manager alive