Beaker
Beaker

Reputation: 1608

Crash when sending via AsyncUDPSocket

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?

Upvotes: 0

Views: 839

Answers (2)

Beaker
Beaker

Reputation: 1608

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!

Upvotes: 1

Seth Noble
Seth Noble

Reputation: 3303

You created the socket, but did you create packet?

Upvotes: 0

Related Questions