AsyncUdpSocket how to use receive

前端 未结 4 1940
甜味超标
甜味超标 2021-01-04 18:23

I am trying to get a program for iPhone running on the simulator. My problem is with receiving UDP data. I use asyncUdpSocket. If I make a socket and use sendData:(NSD

4条回答
  •  心在旅途
    2021-01-04 18:27

    AsyncUdpSocket *socket=[[AsyncUdpSocket alloc]initWithDelegate:self];    
    //receiveWithTimeout is necessary or you won't receive anything
    [socket receiveWithTimeout:-1 tag:2]; //-------here
    NSData *data=[@"Hello from iPhone" dataUsingEncoding:NSUTF8StringEncoding];
    [socket sendData:data toHost:bchost port:9003 withTimeout:-1 tag:1];
    

提交回复
热议问题