0

I'm trying to broadcast via UDP. I included the CFNetworking framwork and added AsyncUDPSocket to my project.

#import "AsyncUdpSocket.h"

I then created a socket as:

    broadcastSocket = [[AsyncUdpSocket alloc] initWithDelegate:self];

and I send data as:

[self.broadcastSocket enableBroadcast:YES error:&error];
[self.broadcastSocket sendData:[@"hello" dataUsingEncoding:NSASCIIStringEncoding] toHost:@"255.255.255.255" port:5538 withTimeout:10 tag:1];

But when I send data, AsyncUdpSocket crashes with EXC_BAD_ACCESS in

- (CFSocketRef)socketForPacket:(AsyncSendPacket *)packet

Specifically at

return ([packet->address length] == sizeof(struct sockaddr_in)) ? theSocket4 : theSocket6;

OR it also sometimes crashes in:

- (void)doSend:(CFSocketRef)theSocket

at

const void *buf  = [theCurrentSend->buffer bytes];

Is there something wrong with how I am making my socket?

2 Answers 2

1

Ah, I see now. I updated to the latest version of AsyncUDPSocket and it requires ARC. There is a warning that it issues that wasn't popping up in my debugger, which is another problem. However, when looking at the source code, it is on line 11. Doh!

Added ARC flag (-fobjc-arc) and it runs fine!

1
  • Thanks a lot, you save my time. I always get error at this line 'const void *buf = [theCurrentSend->buffer bytes];'
    – majorl3oat
    Apr 1, 2014 at 9:39
0

You created the socket, but did you create packet?

3
  • You should be able to simply use the sendData function of AsyncUdpSocket to send a packet. It doesn't need to be manually constructed.
    – Beaker
    Sep 21, 2012 at 0:49
  • The code snippet is incomplete, so it is not clear that when you reference packet that it has actually been initialized at that point. If it hasn't been initialized, or if it has been released, that would account for the crash.
    – Seth Noble
    Sep 21, 2012 at 14:25
  • I'm using an instance of AsyncUdpSocket. You don't need to construct packets manually.
    – Beaker
    Sep 23, 2012 at 5:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.