views:

191

answers:

6

Hi everyone!

I've recently got interested in Linux network programming and read quite a bit (Beej's Guide to Network Programming). But now I'm confused. I would like to write something to have some practice, but I don't know what exactly. Could please recommend me a couple of projects to start with?

Thanks.

+4  A: 

Write a very simple stupid web server which will accept connections on port 80 and serve back pages.

Then you can extend it to support other media download (images etc.).

Then you can add some (prebuilt) script language interpreter which will process pages in PHP, Perl etc.

You'll learn a lot in the process.

Developer Art
Except, don't try to listen on port 80. That requires privileges. List on port 8000. Slightly simpler for beginners.
S.Lott
+3  A: 

I would start by developing a simple multiplayer game like tic-tac-toe:

  • use ncurses (to easily program your gui)
  • manage a lobby in which players can join
  • manage games (started by a players that asks to play to another one)
  • manage ladder or rankings
  • manage a global chat for everyone that joins and a local chat for people that are playing

of course I suggested tic-tac-toe but you could choose another similar game (with simple rules).. the important part is to have to care about many clients that are also playing in couples (to handle data forwarding and game managing) and sending states (like games list) to players.

The good thing of this example is that you have a two-level protocol:

  • first level to handle global action
  • second level to handle a single game
Jack
I had to make a Boggle game like this in school. Learned a lot.
SP
+1  A: 

I can recommend grabbing Wireshark - it will help you understand the to-and-fro of network traffic.

Nate
Although Wireshark is a great product, how it could possibly help someone in learning network PROGRAMMING ?
qrdl
I'd say learning about network flows is vital to network programming. Plus, it can easily help with debugging. And, it's really really interesting :-)
Nate
+3  A: 

I'm not sure how in-depth you want to start your Linux Network Programming career, but if you want to just get started with dealing with sockets, probably the easiest examples are a Producer/Consumer pairing or an Echo Server. Another good source would be looking at some of the examples/assignments from any number of University/College courses on Distributed computing.

Producer/Consumer

This could be run in a pair of terminals on your computer to test. Create two applications:

  • Producer program starts with a hostname and port, takes a line of input from the user, connects to the Consumer, sends it the input, asks for another line of input, and finishes when it reaches EOF (Ctrl-D).
  • Consumer program starts with a listening port, waits for a connection from the Producer, reads the message sent by the Producer, outputs that message, closes the connection with the Producer, exits gracefully when sent an interrupt (Ctrl-C).

Echo Server

Similar idea to Producer/Consumer.

  • Echo Server starts with a listening port, waits for a connection, reads a message from the Client, sends that same message back to the Client, and exits gracefully when sent an interrupt (Ctrl-C).
  • Echo Client starts with a hostname and port, takes a line of input from the user, connects to the Server, sends the input, reads back the response, compares the two to verify it was an echo, asks for another line of input, and finishes when it reaches EOF.
Ophidian
I like the `Echo` idea a lot. You could simplify further by making it a `Ping` like pair :)
Matthieu M.
+1  A: 

I suggest finding any computer networks laboratory course page and solve the relevant assignments. There you'll find detailed explanation of problem and assignments will be in the increasing order of complexity. You can find such webpages by searching this in Google "inurl:edu computer networks lab assignments". (without qoutes)

Here are some excellent assignments (with very detailed explanations). Try to implement all of them in this order

http://www.facweb.iitkgp.ernet.in/~agupta/netlab/Assgn1.pdf

http://www.facweb.iitkgp.ernet.in/~agupta/netlab/Assgn2.pdf

http://www.facweb.iitkgp.ernet.in/~agupta/netlab/Assgn3.pdf

http://www.facweb.iitkgp.ernet.in/~agupta/netlab/Assgn5.pdf

http://www.facweb.iitkgp.ernet.in/~agupta/netlab/Assgn6.pdf

http://www.facweb.iitkgp.ernet.in/~agupta/netlab/Assgn7.pdf

claws
A: 

The book to read is Unix Network Programming by R. Stevens: http://www.kohala.com/start/unpv12e.html

The project to do is a TCP Proxy or a Web Proxy. Make it single-threaded but of course handle multiple connections. You should be able to finish it in one week of spare-time work.

MK