Listen on a UDP Port
Listen on a UDP Port
- Subject: Listen on a UDP Port
- From: "Bridger Maxwell" <email@hidden>
- Date: Thu, 14 Feb 2008 01:45:52 -0700
Hello, I know the topic of UDP sockets must come up quite a bit. I know
because I just spent a while searching the list's history. Although I read
a ton of posts on UDP sockets and how they may or may not be implemented
easily in a Cocoa networking wrapper, I still can't make heads or tails of
the situation. My problem is really quite simple. I would like to listen
on a socket for incoming UDP packets. I have the code written, but it is
listening on a TCP socket. Could I change it to listen on UDP without
affecting the other functions (i.e. receiveMessage)? I am still very new at
Cocoa, and most of this code is pulled from an example I found online. Any
hints would be appreciated. Does NSSocketPort even support UDP?
- (id)initWithPortNumber:(int)portNumber
{
if( self = [super init] ) {
NSSocketPort *socketPort = [[NSSocketPort alloc] initWithTCPPort
:portNumber];
int fd = [socketPort socket];
fileHandle = [[NSFileHandle alloc] initWithFileDescriptor:fd
closeOnDealloc:YES];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self
selector:@selector(receiveMessage:)
name:NSFileHandleReadCompletionNotification
object:fileHandle];
[fileHandle acceptConnectionInBackgroundAndNotify];
return self;
} else {
return nil;
}
}
Thank You,
Bridger Maxwell
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden