• 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
Re: Substituting low level BSD stuff with spiffy Cocoa calls
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Substituting low level BSD stuff with spiffy Cocoa calls


  • Subject: Re: Substituting low level BSD stuff with spiffy Cocoa calls
  • From: Andrew Zamler-Carhart <email@hidden>
  • Date: Wed, 15 Dec 2004 12:38:54 +0000

Dear Malte,

One "strictly Cocoa networking solution" is called Distributed Objects.

http://developer.apple.com/documentation/Cocoa/Conceptual/DistrObjects/Concepts/AboutDistributedObjects.html

I have some sample code for how to use it here:

http://www.kavasoft.com/DistributedWidgets

There is extensive support in the Objective-C language itself for DO:

http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/RuntimeOverview/chapter_4_section_5.html

Best regards,

Andrew
KavaSoft

On Dec 15, 2004, at 5:09 AM, Malte wrote:

Hey *
since this is both, a network and cocoa related problem, i wasn't sure which list to post this to and thus sent it to both, the networking and the cocoa list.

here is my problem:

I'm currently trying to set up a little "networking-testing-cocoa-app". I've plowed through the net finding countless tutorials about
BSD sockets but oddly enough not one "clean objective-c/cocoa"-networking tutorial. :(

So following a tutorial that builds a little chat-application (written by Mike Beam on macdevcenter.com) he, too, uses the unsightly BSD stuff in his otherwise spiffy cocoa/objective-c app. I figured that i'd just "clean up the code" by replacing the BSD stuff with the (apparent) cocoa equivalent but somehow this isn't working too great. After a few days of trying to get a strictly Objective-C/Cocoa solution up and running i have decided to throw the towel into the ring and turn to the lists. I hope one of you has both, the knowledge and patience to help me out :(

Here is the original code by Mike from his tut (Mike, in case you're reading the list: thanks for the tutorials you put together ;))
[snip]
struct sockaddr_in addr;
int sockfd;
// Create a socket
sockfd = socket( AF_INET, SOCK_STREAM, 0 );
// Setup its address structure
bzero( &addr, struct sockaddr_in));
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl( INADDR_ANY ); // Bind to any of the system addresses
addr.sin_port = htons( 0 ); // Let the system choose a port for us
// Bind it to an address and port
bind( sockfd, (struct sockaddr *)&addr, struct sockaddr));
// Set it listening for connections
listen( sockfd, 5 );
// Find out the port number so we can pass it to the net service initializer
int namelen = struct sockaddr_in);
getsockname( sockfd, (struct sockaddr *)&addr, &namelen );
// Create NSFileHandle to communicate with socket
listeningSocket = [[NSFileHandle alloc] initWithFileDescriptor:sockfd];
[snip]
what follows is the NSNotificationCenter stuff and so on.

So i figured i could abbreviate the whole ugly thing by doing so:
[snip]
struct sockaddr_in addr;
int sockfd;


NSSocketPort * cocoaStyleSocket = [[NSSocketPort alloc] initWithTCPPort:0];
// Create a socket
sockfd = [cocoaStyleSocket socket];
// Create NSFileHandle to communicate with socket
listeningSocket = [[NSFileHandle alloc] initWithFileDescriptor:sockfd];
[snip]
But after this modification the app doesn't work anymore. There are endless invocations of the "receiveMessage"
method which is being triggered by the NSNotificationCenter when the user initiates a connection by double clicking the
rendezvous contact from his list.
Also no messages are being sent/received anymore --> the chat application isn't working.

Maybe something in the code snippets above is painfully obvious to some of you but i'm such an amateur that i can't
figure it out. :(
By now i guess i could easily write my little app using the BSD sockets, alright, but it has gotten to the point where i want to get
the Obj-C/Cocoa way to work just as a proof of concept so to speak.

I am very grateful for any advice!

Thanks a lot,

-malte the not-so-hot networker _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Substituting low level BSD stuff with spiffy Cocoa calls (From: Malte <email@hidden>)

  • Prev by Date: Re: Getting Pixel values of an image
  • Next by Date: Re: one document at a time
  • Previous by thread: Re: Substituting low level BSD stuff with spiffy Cocoa calls
  • Next by thread: time during login its OK to display windows
  • Index(es):
    • Date
    • Thread