I use a AsyncSocket.h, AsyncSocket.m
Send function
read a lot of articles on the introduction ofThis is the send function
I use the service side- (Void) socket: (GCDAsyncSocket *) sock didReadData: (NSData *) data withTag: (long) tag
{
NSString * receive = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
if (receive == NULL)
{
NSLog (@ "Data is null");
}
else
{
[Self addText: [NSString stringWithFormat: @ "% @", receive]];
NSString * recv = [NSString stringWithFormat: @ "received:% @", receive];
NSLog (@ "fasong% @", recv);
[S readDataWithTimeout: -1 tag: 0];
}
Below is my own writing
- (IBAction) recvData: (id) sender
{
/ * NSData * message = [[NSData alloc] init];
[Socket readDataToData: message withTimeout: -1 tag: 0];
NSString * Str = [[NSString alloc] initWithData: message encoding: NSUTF8StringEncoding];
NSUInteger len = [Str length];
[Self addText: [NSString stringWithFormat: @ "message sent by the client:% @", Str]];
NSLog (@ "message sent by the client:% @,% lu", Str, len);
[Socket readDataWithTimeout: -1 tag: 0]; * /
}
But these two did not receive data ah
didReadData received what is sent to the client data, or are there SOCDET data
I can do that function
Reply:
- (Void) socket: (GCDAsyncSocket *) sock didReadData: (NSData *) data withTag: (long) tag
Is a callback method
Socket Socket assembly when data is receivedYou can not write
Reply:
Thanks for the answer, I asked a former classmate, to find the problem, I was not careful, the part of the agent to set commented out,
(Void) socket: (GCDAsyncSocket *) sock didReadData: (NSData *) data withTag: (long) tag can receive data
No comments:
Post a Comment