Sockets (6)

1 Name: #!/usr/bin/anonymous : 2009-09-25 13:09 ID:+nDvn20/

I'm thinking about learning how to send and recieve packets, as a stream or something. I know C a lot. You guys know where I can get some examples on how to download something (with HTTP) or just make 2 programs talk to each other?

Whenever I make an app that downloads something I end up using wget and system() calls, that sucks, and I feel bad about it. So I wanna change that.

2 Name: #!/usr/bin/anonymous : 2009-09-25 15:11 ID:Heaven

look at the source for netcat. it's about the most straightforward socket program there is.

3 Name: #!/usr/bin/anonymous : 2009-09-26 10:55 ID:Z9WVycSV

>>1
Then you have to delve into networking. Networking is supported in a different manner by different machines, programming languages, libraries, et cetera, but they all follow the same protocols of course.

So, the first question to ask OP, is this: For which operating system are you inetrested to have your code run? POSIX, which is the UNIX standard, provides a socket interface. WinAPI also has a socket interface (and by the way, WinAPI has almost copied the socket interface of POSIX, which is based on the original implementation on BSD, for which you may find the complete source code and documentation in TCP/IP Illustrated volume 2).

First thing you have to do is understand what is C and what is "extension" to C: C is the programming language defined by some standard and has nothing to do with networking, protocols, et cetera. What you get from POSIX is a library that you can use for these tasks. Also, don't forget that you'll have to learn both networking theory and the corresponding POSIX functions. Which should you do first? Well, luckily for you, there's an excellent book which is called UNIX network programming (http://www.kohala.com/start/unpv12e.html), which will introduce you to both at the same time.

There's still a problem though: You're learning only part of POSIX, which is the networking interface; it'll be good for you if you first got an idea for what POSIX is really about, so you can read another book first, called advanced programming in the unix environment (http://www.kohala.com/start/apue.html). This will teach you UNIX and POSIX. You'll learn how to handle all sorts of files and all their attributes (special devices, named or not pipes, files, user/group/other right, fcntl() et cetera). I guarantee to you >>1, that if you do take my advice you will be someone who has a very good understanding of unix, C, and networking at the same time.

>>2
That's just MEAN. You can't advice a newbie to look at that. If this suggestion is serious, you must be a complete newbie yourself (else you'd know how different is what OP is asking with what you gave him). If anyone is interested in having a more elaborated answer as to why >>2's suggestion is not good, I'll provide it, but there's no need to waste time if there's no demand.

4 Name: #!/usr/bin/anonymous : 2009-09-26 19:58 ID:Heaven

>>3

> If anyone is interested in having a more elaborated answer as to why >>2's suggestion is not good, I'll provide it, but there's no need to waste time if there's no demand.

I am downloading the source for netcat as I type this; I enjoy reading source code as means of picking up new techniques and concepts. Like the OP I have no real working knowledge of writing networking applications. So I am certainly interested in hearing why you feel >>2's suggestion is not good.

5 Name: #!/usr/bin/anonymous : 2009-09-26 20:29 ID:Heaven

>>4
Okay, why don't you tell us instead what you learned from reading netcats source code? Seriously now, netcat is a big project because you probably mean gnu netcat which, like any gnu utility, is filled with implementation-dependant issues and work-arounds, has a lot of options to parse, doesn't actually make use of any higher level protocol (which the OP clearly asked for), and it's just a lot of lines to read compared to a book and the knowledge you'll get from that.

6 Name: #!/usr/bin/anonymous : 2009-09-28 04:19 ID:CRkM3sbz

The Beej's guide to networking: http://www.beej.us/guide/bgnet/

This thread has been closed. You cannot post in this thread any longer.