• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Listen on a UDP Port
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Listen on a UDP Port
      • From: "Hamish Allan" <email@hidden>
  • Prev by Date: RE: In-loop releasing of objects does not free memory?
  • Next by Date: Re: MD5 check sum of a file
  • Previous by thread: Re: NSComboBox / NSTableView help
  • Next by thread: Re: Listen on a UDP Port
  • Index(es):
    • Date
    • Thread