GCDAsyncSocket server receive data only first time

前端 未结 2 665
广开言路
广开言路 2021-02-04 18:18

Client sent message every time when I press send button but Server receive message only first time. What is the issue in server

Server:

         


        
2条回答
  •  心在旅途
    2021-02-04 18:41

    You have to make a read call from your server class in didReadData: delegate. Rest is fine. Use below code.

    -(void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag {
    
       [sock readDataWithTimeout:-1 tag:0];
    
        NSString *msg = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
        NSLog(@"MSG: %@",msg);
    }
    

提交回复
热议问题