Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Cocoa Networking

Cocoa Networking
Thread Tools
Mac Elite
Join Date: Mar 2001
Location: England
Status: Offline
Reply With Quote
Jun 20, 2005, 04:41 PM
 
I'm after info on cocoa networking. I'm a novice developer (to Cocoa, anyhow) and am trying to learn Cocoa programming by working on a project. This project is a client for a multi-user bell ringing simulator (spec here) that a friend is writing.

I'm after what framework to use to take care of the networking. I would ideally like something that I could set listening and then whenever it receives a packet it calls a delegate, or something along those lines. The problem is packets are variable length, so I can't ask it to read for a certain length at a time.

I've looked at Omni's networking framework but it seems to require multithreading. I've also looked at AGKit which looks ok, but has not been updated for a while.

Is there anything built into Cocoa that I could use? NSFileHandle seems to read to the end of the file each time, not to whatever the packet separator character is (it's probably a \n newline). I have no problem only targetting Tiger if there are some new APIs.

Thanks for your help.

Amorya
What the nerd community most often fail to realize is that all features aren't equal. A well implemented and well integrated feature in a convenient interface is worth way more than the same feature implemented crappy, or accessed through a annoying interface.
     
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status: Offline
Reply With Quote
Jun 20, 2005, 06:11 PM
 
You can use NSFileHandle and maintain the packet state yourself. In other words, you keep an accumulator into which you place any incoming data. Whenever you get new data, check the accumulator - if you've got a complete packet in there, pull it out, process it, and leave whatever is left to keep on accumulating.

The Chicken of the VNC source code illustrates this technique.
Geekspiff - generating spiffdiddlee software since before you began paying attention.
     
Amorya  (op)
Mac Elite
Join Date: Mar 2001
Location: England
Status: Offline
Reply With Quote
Jun 20, 2005, 08:20 PM
 
Could I have it send a message to one of my objects when there was data to be read? I imagine it would use delegates... If I used the accumulator idea, I could have one object (WBLPacketProcessor or something) that split it into packets and then sent on the required message - but it'd need to be called at the appropriate time.

People around me are suggesting using a big loop. I'm at a LAN party surrounded by non-OO programmers

Amorya
What the nerd community most often fail to realize is that all features aren't equal. A well implemented and well integrated feature in a convenient interface is worth way more than the same feature implemented crappy, or accessed through a annoying interface.
     
Fresh-Faced Recruit
Join Date: Dec 2001
Location: Wisconsin
Status: Offline
Reply With Quote
Jun 20, 2005, 08:45 PM
 
I made a few simple additions to smallsockets awhile ago that does pretty much what you asked. I can send it to you someway if you want.
     
Amorya  (op)
Mac Elite
Join Date: Mar 2001
Location: England
Status: Offline
Reply With Quote
Jun 20, 2005, 09:09 PM
 
Yes please! My email is:

amorya at amorya dot freeserve dot co dot uk

Replace at with @ and dot with .


Cheers

Amorya
What the nerd community most often fail to realize is that all features aren't equal. A well implemented and well integrated feature in a convenient interface is worth way more than the same feature implemented crappy, or accessed through a annoying interface.
     
Mac Elite
Join Date: Oct 1999
Location: San Jose, Ca
Status: Offline
Reply With Quote
Jun 20, 2005, 09:36 PM
 
Um... why are you not just using distributed objects?

Apple's page
CocoaDev's page
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jun 20, 2005, 10:57 PM
 
Originally Posted by larkost
Um... why are you not just using distributed objects?
Presumably because the server that the client is supposed to connect to doesn't use DO?
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Amorya  (op)
Mac Elite
Join Date: Mar 2001
Location: England
Status: Offline
Reply With Quote
Jun 21, 2005, 04:53 AM
 
Originally Posted by Chuckit
Presumably because the server that the client is supposed to connect to doesn't use DO?
Yup

Server is (I think) written in plain C. There will eventually be many clients for different OSs.

Amorya
What the nerd community most often fail to realize is that all features aren't equal. A well implemented and well integrated feature in a convenient interface is worth way more than the same feature implemented crappy, or accessed through a annoying interface.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:17 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2