Hi,

I have a device which basically outputs a UDP data stream. FYI the protocol specs are at : http://www.enttec.com/docs/enttec_protocol.pdf

I found a really helpful post on the forum here titled : Re: Listen on a UDP Port( http://lists.apple.com/archives/cocoa-dev/2008/Feb/ msg01180.html ) which has really helped me build the framework.

However, I am stuck in 2 ways now - being pretty new to Cocoa also doesn't help.

I guess, I don't fully understand the code posted enough because I can't seem to access the dictionary object created and posted to the notifications with the previous example. (FYI my actual code is in appendix 1 below) [[NSNotificationCenter defaultCenter] postNotificationName:@"NSFileHandleReadCompletionNotification"
  object:[NSDictionary dictionaryWithObject:[NSData dataWithBytes:&msg
  length:(n * sizeof(u_char))]

Secondly, the device has "Null" bytes in the output stream and I am guessing if I get the data into a NSString object, when trying to parse the string, it will terminate because of the Null. And I know that the start of the UDP message (based on the protocol) is ESDD<<Null or 00 hex>>.... and confirmed with a packet sniffer app too (appendix 3), so I can see that when treating as a string, the data will be truncated at the first "Null".

So if anyone could also help with an idea on how to work with such a data stream, I'd be really grateful.

many thanks


Jason


1.  SocketCall Back Code
static void socketCallback(CFSocketRef cfSocket, CFSocketCallBackType
type, CFDataRef address, const void *data, void *userInfo)
{
  u_char msg[MAX_UDP_DATAGRAM_SIZE];
  struct sockaddr_in from_addr;
  socklen_t addr_len = sizeof(struct sockaddr_in);
size_t n = recvfrom(CFSocketGetNative(cfSocket), (void *)&msg, MAX_UDP_DATAGRAM_SIZE, 0, (struct sockaddr *)&from_addr, &addr_len);
        
NSLog (@"socketCallback (DMX event). >%s< %i bytes", &msg, (n * sizeof(u_char)));
                                                                                
                        
[[NSNotificationCenter defaultCenter] postNotificationName:@"NSFileHandleReadCompletionNotification" object:[NSDictionary dictionaryWithObject:[NSData dataWithBytes:&msg length:(n * sizeof(u_char))] forKey:@"NSFileHandleNotificationDataItem"]]; // How do I retrieve the data from this object in my notification subscription code?
}


2. NS Log output of the above:
2008-03-16 18:12:08.214 lightapp[10014] socketCallback (DMX event). >ESDD< 521 bytes

3. Packet Sniffer output is:
Headerlength: 522 bytes, Data follows:

00000 45 53 44 44 00 00 01 02 00 00 03 05 00 00 05 05 ESDD............ 00010 00 00 03 03 c6 39 00 00 00 00 02 02 04 04 00 05 ..... 9..........
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to