Hello Community,
my first post and also my first question. I am currently playing around with the Artnet protokoll, which is based on UDP. Trying to develop an Cocoa Application that reads Artnet data. I decided to use the AsyncUDPSocket Cocoa framework and got it working somehow.. So when i try to send a packet to my listen port using
nc -u localhost 6454
my delegate gets called. If i try this with another Artnet application my delegate never gets called back, but i can see the packets in the packet analyzer..
I suspect it must be something caused by the "tag". Can someone explain the (long)tag variable as i can find no Documentation about this Value and i can find no answer on the net. Also i might add i am relatively new to cocoa developing so maybe it´s a very basic error..
below is my init code for the sockets:
listenSocket_unicast = [[AsyncUdpSocket alloc] initWithDelegate:self]; // This one is not added to the Autorelease pool, so cocoa doesnt delete my socket object.
listenSocket_broadcast = [[AsyncUdpSocket alloc] initWithDelegate:self]; // This one is not added to the Autorelease pool, so cocoa doesnt delete my socket object.
// Bind unicast socket..if adress is not the loopback device
if (![SocketAddress isEqualToString:@LOOPBACK])
if ([listenSocket_unicast bindToAddress:SocketAddress port:ARTNET_PORT error:nil] == NO)
{
NSLog (@"Could not bind unicast socket on Adress %@ and port %i",SocketAddress, ARTNET_PORT);
return NO;
}
else NSLog (@"Unicast Socket bind to on Adress %@ and port %i",SocketAddress, ARTNET_PORT);
// Bind broadcast socket..
if ([listenSocket_broadcast bindToAddress:SocketBroadcastAdress port:ARTNET_PORT error:nil] == NO)
{
NSLog (@"Could not bind broadcast socket on Adress %@ and port %i",SocketBroadcastAdress, ARTNET_PORT);
return NO;
}
else
NSLog (@"Broadcast Socket bind to on Adress %@ and port %i",SocketBroadcastAdress, ARTNET_PORT);
[listenSocket_unicast receiveWithTimeout:-1 tag:0];
[listenSocket_broadcast receiveWithTimeout:-1 tag:0];
[listenSocket_broadcast enableBroadcast:YES error:nil];
and the code i currently try to get working:
-(BOOL)onUdpSocket:(AsyncUdpSocket *)sock didReceiveData:(NSData *)data withTag:(long)tag fromHost:(NSString *)host port:(UInt16)port
{
[sock receiveWithTimeout:-1 tag:0];
NSLog (@"UDP Delegate executed");
return YES;
}
Thanks in advance,
matthias