PDA

View Full Version : Mac API for networking?




dancks
Feb 25, 2012, 10:32 AM
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.



KnightWRX
Feb 25, 2012, 11:06 AM
You can go very low-level and just use the BSD socket API.

This page should cover it :

http://www.cs.vu.nl/~jms/socket-info.html

Apple has higher level stuff if you don't want to learn the "RAW" way :

https://developer.apple.com/library/mac/#documentation/Networking/Conceptual/CFNetwork/Concepts/Concepts.html

chown33
Feb 25, 2012, 11:54 AM
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.

KnightWRX
Feb 25, 2012, 12:05 PM
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.

I assume the OP means in C :

I asked my teacher awhile back he said there are networking specific headers 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).

subsonix
Feb 25, 2012, 12:09 PM
Look for a socket api for what ever language or framework you intent to use, it's available for most of them.

robvas
Feb 25, 2012, 06:49 PM
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.

Here you go!

http://beej.us/guide/bgnet/output/html/multipage/index.html

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

dancks
Feb 26, 2012, 07:54 AM
You can go very low-level and just use the BSD socket API.

This page should cover it :

http://www.cs.vu.nl/~jms/socket-info.html

Apple has higher level stuff if you don't want to learn the "RAW" way :

https://developer.apple.com/library/mac/#documentation/Networking/Conceptual/CFNetwork/Concepts/Concepts.html

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.

KnightWRX
Feb 26, 2012, 08:20 AM
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.

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