Socket Library on OSX?

Member
Posts: 148
Joined: 2003.03
Post: #1
Hi.

I'm looking for a good, easy-to-use socket library for Carbon.
I found some good ones for Cocoa (NetSocket, AsyncSocket), but sadly, I've moved on from Cocoa to bigger and brighter things.

I know I could write my own using CFNetwork, but I figure that somebody must have done it already. I don't really want to concern myself with the low-level programming as of yet; I just want to play around with high-level networking with C++. So I'm looking for the quickest/easiest way out.

So, can anybody recommend a good socket library for Carbon? Preferably one that encompasses CFNetwork into a handy C++ class. I've read about BSD sockets, and I'm sure there are dozens of classes ready for use, but I'd still like to get a recommendation from some sort of professional.

Thank you.
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #2
Believe me, many professionals use BSD sockets. Rasp I've used them myself, and they are quite easy to use. (and are compatible with Linux and even Windows, with winsock)
Quote this message in a reply
Member
Posts: 148
Joined: 2003.03
Post: #3
Can you recommend a specific BSD socket class/library for OSX and C++?

I hate to sound picky, but this is what I'm looking for:

1) Automatic handling of all the nifty DNS stuff
2) Installation/compile instructions if it isn't a simple 'make -MACOSX'
3) Documentation and/or tutorials
4) C++ compatability
5) Cross-platform is a plus

If you know of one, please clue me in.
I've been searching all day. I came close a couple of times, but no luck.

Thanks.
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #4
I don't know of any C++ classes, but unless you're pressed for time, why not make your own? The C API is pretty straight forward, and it should be relatively easy to make a C++ wrapper to do everything you want. This is the site that I learned all my socket stuff from. The last tutorial on the bottom shows a client and server for over a network, which can be easily adapted to use a custom port etc. Look up the man pages if you want to know more about the specific functions.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #5
Wait, "bigger and brighter" things than Cocoa? And now you want something to do with Carbon? Don't contradict yourself!
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #6
This is how to use sockets:
http://beej.us/guide/bgnet/output/htmlsingle/bgnet.html

Any wrapper library is just going to be more confusing, less well documented and have more bugs.
Ive not seen any wrappers that are worthwhile.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Member
Posts: 148
Joined: 2003.03
Post: #7
Like I said, I could write my own socket library easily with CFNetwork; but in keeping with the oft-given advice: why reinvent the wheel? The socket wheel has been invented, right? I just figured there _must_be_ a suitable OSX-compatible C++ BSD sockets library that somebody here at iDevGames could perhaps recommend as to save me weeks of struggling to develop and test my own. All I want is to do some simple networking alongside a C++ library that isn't AppKit compatible, but I'm finding it hard to find a good socket library to use in Carbon.

And what I meant by 'bigger and brighter' was that I've long since stopped focusing on Cocoa and have moved on to a more cross-platform methodology. I didn't mean to flame Cocoa. Sorry if it was taken as such.

So...let me rephrase my question: if anybody out there knows of a decent C++ BSD socket library (or better yet, a CFNetwork C++ class) for OSX, can you please let me know about it? Thanks.
Quote this message in a reply
Member
Posts: 204
Joined: 2002.09
Post: #8
Perhaps you could elaborate what it is you want this library to provide. I'm with the majority here that you don't need more than sockets or CFNetwork for simple networking, but perhaps your're looking for more? Something to handle concepts of "players" and "games" and such? If so, you might try OpenPlay.
Quote this message in a reply
Member
Posts: 148
Joined: 2003.03
Post: #9
[FIXED]

This was absolutely unnecessary imho: http://www.idevgames.com/forum/showthread.php?p=123329
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #10
Writing a socket wrapper shouldn't take weeks. It should take you maybe a day to learn about sockets, knowledge you should probably know anyway for using them, and maybe a few hours to write the actual class.
Quote this message in a reply
Member
Posts: 148
Joined: 2003.03
Post: #11
Yes, "weeks" was an exaggeration, but you get the idea.
Like I said, I'm just trying to do some simple tests. If nobody wants to give up the goods, then that's fine, I'll just use OpenPlay. :-D

I'm still open to any suggestions for a good OSX compatible C++ BSD sockets library.
Quote this message in a reply
Member
Posts: 87
Joined: 2006.08
Post: #12
CFNetwork is actually an extremely convenient API to use in a Runloop based program. Why the insistence on a C++ wrapper? Either straight BSD sockets or CFNetwork itself are entirely functional in a C++ program.

It sounds like you're making the 'I'm using c++, and absolutely everything must be an object' mistake. (and it is a mistake).
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #13
Agreed about being a mistake to make everything a class. One of my big problems with Java (and similar languages) is forcing you into the OO paradigm, as it's often simpler to leave things in a procedural form. I can see sockets as being able to go either way, though, whether you think the simple integer returned by socket as enough or if you want it encapsulated inside an object that puts the socket into the read/write functions etc. for you. (it's probably a good idea to put a wrapper over those functions, though, so you can handle things like putting in a timeout and having data left over if it took too long to send/receive all of the data; you just have to decide if you want to put it in a function that takes a socket as a parameter or make it part of an object that has a socket in it)
Quote this message in a reply
Member
Posts: 148
Joined: 2003.03
Post: #14
I've since moved on to actually writing my own BSD socket class. I did my tests with OpenPlay successfuly and now I am satisfied.

Anway, I wasn't looking for a class specifically. Like I stated countless times, I was just trying to do some quick tests. So I was looking for _ANYTHING_ that would permit me to quickly setup networking without having to concern myself with the technical aspects. A class...a library...a magic wand...anything. OO design patterns were the last thing on my mind.

OpenPlay was more than suitable for what I needed. Now that I was able to do my experiments, I was able to see that adding networking is feasible. This is all I wanted to do. If networking wasn't feasible, then I would have wasted days writing and testing my own network code. Am I a bad person for wanting convenience? This is the internet age isn't it?

About the OO thing: that is all subjective. OO-networking may be suitable for one project while it may not be so much so for another. My game engine is highly OO'd and open-ended, so wouldn't it make sense to stay with that design pattern? I really don't know since I've never done networking with C++.

Thanks for your help guys.
Quote this message in a reply
Member
Posts: 37
Joined: 2006.08
Post: #15
OneSadCookie Wrote:Wait, "bigger and brighter" things than Cocoa? And now you want something to do with Carbon? Don't contradict yourself!

My thoughts exactly Rolleyes
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  How to check if data come in from the socket without hanging there!!! KingdomHeart 2 5,789 Nov 23, 2007 09:25 AM
Last Post: KittyMac
  OpenGL + Socket!!! Flush socket problem!!! KingdomHeart 4 4,801 Nov 21, 2007 10:14 AM
Last Post: Zekaric
  BSD Socket: Send Data but never Receive kodex 2 7,972 Jul 1, 2005 10:56 PM
Last Post: kodex
  Cocoa Socket Control? SummerLand 4 5,470 Dec 1, 2002 01:52 AM
Last Post: Gastropod