1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Mac API for networking?

Discussion in 'Mac Programming' started by dancks, Feb 25, 2012.

  1. macrumors member


    I'm learning about networking, and I would like to apply what I'm learning by making a chat-type application and send packets on the network. (one side would be an AI type thing). For ports I would probably use the high port numbers reserved for random conversation assignment. I'm curious how I would go about doing this. I asked my teacher awhile back he said there are networking specific headers in C and there are usually a port or some freeware to communicate with lower level data link or networking layer. Is this possible? I'm a little lost on where to get started.
  2. macrumors Pentium


  3. macrumors 603

    What language do you intend to program this in?

    There are shell commands you can use to send and receive network packets at a fairly high level. The 'nc' command (a.k.a. netcat) can both send and receive, using TCP or UDP. The 'curl' command can use the HTTP, FTP, and other protocols.

    Other languages, such as perl, python, C, C++, Objective-C, Java, JavaScript, etc. have their own networking functions and classes.
  4. macrumors Pentium


    I assume the OP means in C :

    (Nitpick : his teacher is actually wrong, there are no networking specific headers in C. C doesn't know about networking. Ultimately, networking is a platform specific endeavour. In OS X, it's either BSD sockets or higher level Apple frameworks for C work).
  5. macrumors 68040

    Look for a socket api for what ever language or framework you intent to use, it's available for most of them.
  6. macrumors 68000

    Here you go!


    If you want to make a chat program (to type in) and server (for the AI to be in) you are going to put the code in something like a CFRunloop
  7. macrumors member


    Thanks KnightWRX I'll definitely check out both but like you said I was interested in something C specific. I remember stumbling across a wiki page about a C header that had a packet header struct. It might have been part of a bigger library. If only I could remember what that was. Also robvas, I'll give a look.
  8. macrumors Pentium


    Both of the links I gave you are C implementations. C itself has no networking sub system in the standard ANSI library.

Share This Page