L4: Learning C, Servers, Low level socket programming

Knocking off the languages one by one. Only significant one left is Java, I think. And Perl I guess.

I’m learning from the venerable K&H second edition, so…guess I’m on the right track. I’ll just put some notes here:

  • C needs the path to be able to run its program. a.out doesn’t work but ./a.out does
  • You have to declare variables, pfft
  • Actually takes a long time to compile.
  • C data types: int, float, char, short (shortint), long (longint), double (double precision float)
  • Types of output replacements: %d print decimal integer, %6d pring decimal integer at least 6 char wide, %f print floating point, %.2f for floating pt 2 chars after decimal point, %6.2f print floating point 6 chars 2 after decimal point, %o for octal, %x for hexadecimal, %c for  character,%s for string
  • Symbolic constants are basically variables and I think they’re retarded.
  • Function declaration requires output and input type

The rest of the book was a quick skim.

—-

How does a server actually work?

I know it receives requests from clients and does the corresponding action (serve files, change files). How does it do this?

Here are the things I have to learn:

  • HTTP Protocol
  • TCP server - BSD socket programming

I’m going to write a server in Python.

Here are useful links:

http://www.kellbot.com/2010/02/tutorial-writing-a-tcp-server-in-python/

http://fragments.turtlemeat.com/pythonwebserver.php

http://evolt.org/node/60276/

http://docs.python.org/library/socket.html

Turns out python makes it ridiculously easy using built in modules. For one, the socket module handles everything socket related. There’s also a module called BaseHTTPServer…you can guess what that does.

Anyway, I wrote four different client/server models and I think I’m pretty satisfied with my knowledge of socket programming and server/client interactions. I need to read into IPv4 and IPv6, the HTTP protocol, and the source code on some of the python socket operations to have a better understanding though…I also want to set up a server box running Apache, and read the Apache source code to see how a real production server works. I just need a cheap machine to do it on…do I? I could just use a virtual machine right? Amazon?

Tags: oneyeardev