UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

  • Index
  • » C
  • » Socket program doubt

#1 2010-07-22 06:07 PM

gwp123
Guest

Re: Socket program doubt

Hi folks,

I am a beginner in Socket Programming. I am trying to do some simple stuff but had a basic query.

I would like to implement something like wget in C top of a TCP socket (i.e., without using any HTTP libraries). Just provide a URL (Example-- $wget www.foo.com/bar.pdf) on the command line, construct a HTTP GET request to download the file identified by the URL, and download and save the file.

Right now trying this only for static HTTP content.

Can someone point out how to begin? What are the steps involved?

Thanks in advance.
BBM

#2 2010-07-22 08:38 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,829
Website

Re: Socket program doubt

I assume this is just for learning purposes?  Because, for real-world app use, you'd
almost definitely be better off using a ready-built library that speaks HTTP for you,
such as libcurl...

Well, first you'll want to at least skim through the HTTP specs to know what to
send and what to expect in reply...  And, you'll also need to know how to parse URLs...

Then, it's just a matter of creating a TCP socket, connecting to the host and port (80
by default for "http:" URLs) from the URL, and sending the appropriate GET request
with appropriate HTTP headers, and then reading and parsing the reply...

Offline

  • Index
  • » C
  • » Socket program doubt

Board footer

Powered by FluxBB