UnderstandingObjective-CLowerHeavy LoadYou should pay attention to the content described in this article. If you do not need to mention it, You can directly go to the topic and use ASyncSocket to create a simple TCP client program. It is a very simple program. Is to call AsyncSocket ConnectToHost to connect to the server.
-
- NSString * host = @"192.168.2.151";
- int port = 35000;
-
- asyncSocket = [[AsyncSocket alloc] initWithDelegate:self];
- NSError *err = nil;
-
-
- if(![asyncSocket connectToHost:host on:port error:&err])
- {
- NSLog(@"Error: %@", err);
- }
The entire program can be compiled and run. When the code is run on connectToHost, the following message is displayed:
- *** -[AsyncSocket connectToHost:on:error:]:
- unrecognized selector sent to instance 0x3e6f250 2011-01-03 23:24:19.423 HelloiPhone[305:20b]
- *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '
- *** -[AsyncSocket connectToHost:on:error:]: unrecognized selector sent to instance 0x3e6f250'
If a breakpoint is set in connectToHost, it cannot be accessed. N-plus nslogs are not displayed. Read ASyncSocket. At last, the flash suddenly appeared. Is it a problem of method overloading?
Because the original method definition is
- - (BOOL)connectToHost:(NSString*)hostname onPort:(UInt16)port error:(NSError **)errPtr;
After the code is adjusted, it is found that the main reason is the onPort parameter symbol. When a method is defined, the parameter symbol serves as a comment and is alsoHeavy LoadSign. When calling a method, the parameter symbol must be kept intact on the call method. When I write onPort as on, the corresponding method cannot be found.
Therefore, the error "unrecognized selector sent to 0x3e6f250" is returned. Here, 0x3e6f250 is the class pointer address of asyncSocket.
Therefore, the following code is modified and runs successfully.
- NSString * host = @"192.168.2.151";
- unsigned short port = 35000;
-
- asyncSocket = [[AsyncSocket alloc] initWithDelegate:self];
- NSError *err = nil;
-
-
- if(![asyncSocket connectToHost:host onPort:port error:&err])
- {
- NSLog(@"Error: %@", err);
- }
When you see the running prompts such as unrecognized selector sent to, your first response should be that the corresponding method is not found. If it is a method name error, it can be found in the compilation phase. However, if the overloaded methods, especially the prompts for incorrect parameter symbols, are hidden.
However, the general compiler will also have a warning, and a warning will be given when you carefully check the above errors during compilation:
- warnning:'AsyncSocket' may be not respond to '-connectToHost:on:err'
Basically, this warning can be used to verify that the class method does not find the cause.
Summary: UnderstandingObjective-CLowerHeavy LoadPlease pay attention to the content of a problem. I hope this article will help you!