Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

dancks

macrumors regular
Original poster
Nov 8, 2009
100
0
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.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,731
8,407
A sea of green
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

macrumors Pentium
Jan 28, 2009
15,046
4
Quebec, Canada
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

macrumors 68040
Feb 2, 2008
3,551
79
Look for a socket api for what ever language or framework you intent to use, it's available for most of them.
 

robvas

macrumors 68040
Mar 29, 2009
3,240
629
USA
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

macrumors regular
Original poster
Nov 8, 2009
100
0
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...g/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

macrumors Pentium
Jan 28, 2009
15,046
4
Quebec, Canada
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.