0

Hi guys im working on a project at school and I got a problem, I'm able to send UDP packet to different adress but I can't read UDP packet sent to my iPhone, after receiving an UDP packet I want the data to appear in a label, im doing something wrong but I dont know what.....my code :

- (BOOL)onUdpSocket:(AsyncUdpSocket *)sock didReceiveData:(NSData *)data withTag:(long)tag fromHost:(NSString *)host port:(UInt16)port
{
    NSLog(@"Incoming data");

    [sock receiveWithTimeout:1 tag:0];
    NSString *receiveddata = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
  //  NSString *receiveddata = data ;
    self.testudp.text = receiveddata;
    return YES;
}
tshepang
  • 12,111
  • 21
  • 91
  • 136

1 Answers1

0

thats the changes I've made :

AsyncUdpSocket *udpsocket;
udpsocket = [[AsyncUdpSocket alloc] initWithDelegate:self];
[udpsocket enableBroadcast:YES error:nil];
[udpsocket bindToPort:1234 error:nil];
[udpsocket receiveWithTimeout:-1 tag:0];

- (BOOL)onUdpSocket:(AsyncUdpSocket *)sock didReceiveData:(NSData *)data withTag:(long)tag fromHost:(NSString *)host port:(UInt16)port{
    NSLog(@"received data");
    NSString *receiveddata = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
    _testudp.text = receiveddata;