ios Read data at fast rate in UDP -
i establishing udp connection using gcdasyncsocket(ios device). working fine , im able send , receive messages, problem want exchange data fast. can send pretty fast data iphone pc cant @ speed data pc, more specific want able data every 100ms. use function when connect successfully:
-(void)startread { [nstimer scheduledtimerwithtimeinterval:1 target:self selector:@selector(startread) userinfo:nil repeats:yes]; [asyncsocket readdatawithtimeout:-1 tag:0]; }
with can read data 1sec interval if try put 0.1 seconds program freezes.(same values under 1second) im sure im doing wrong here , there way achieve want if know plz help!! thanx
i believe above comment correct, you've not set delegate correctly on init. socket creation should this
gcdasyncudpsocket* udpsocket = [[gcdasyncudpsocket alloc] initwithdelegate:self delegatequeue:dispatch_get_main_queue()]; nserror *error = nil; if (![udpsocket bindtoport:0 error:&error]) { [self logerror:[nsstring stringwithformat:@"error binding: %@", error]]; return; } if (![udpsocket beginreceiving:&error]) { [self logerror:[nsstring stringwithformat:@"error receiving: %@", error]]; return; } nsstring *_host = nil; uint16_t _port = 0; [gcdasyncudpsocket gethost:&_host port:&_port fromaddress:udpsocket.localaddress]; [self loginfo:[nsstring stringwithformat:@"socket setup on host %@:%d", _host, _port]]; [self loginfo:@"socket created successfully."];
unless you're using different version of gcdasyncudpsocket i'm familiar with, correct callback method below method. called automatically when delegate set , packet received on correct port.
- (void)udpsocket:(gcdasyncudpsocket *)sock didreceivedata:(nsdata *)data fromaddress:(nsdata *)address withfiltercontext:(id)filtercontext
Comments
Post a Comment