Question

im new to iOS and objective-c, but im trying to use GCDAsyncSocket I'm using it to contact TCP/IP server for the whole application, in each viewController i want to start sending and receiving from/to server, so each time i alloc new instance of cocaSocket, and it send to the server like im new client.

so how can i make sure that one instance of cocaSocket could be applied to the whole application.

thanks for any response !

Was it helpful?

Solution

Well, you might create the Socket in your AppDelegate and store it in a property.

 // pseudo code - did not check the documentation how to actually create such a beast
 self.socket = [[GCDAsyncSocket alloc] init];

Then in other classes, you may access the app delegate via

(myAppDelegate *) [[[UIApplication sharedApplication] delegate] socket];

I don't think you'll need a singleton here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top