Using librariesThis example is about the simplest code anyone could devise. We are not looking today in order to learn how to write networking code, but to have the simplest possible example that needs networking libraries. server.cThis is just a server, that opens up a port to listen on a network following the tCP protocol, and when a query arrives to run the program readdir and send its result as a reply. readdir.cThis has nothing to do with networking, and is just a program to be run when requested. client.cThis sends a query to a specified host and port. We will be doing a lot of this later, and just need a program to illustrate the idea for now. compile-it.shThis is the point of the example at the moment, it shows that to compile both of our programs we need to ask the system to link them together with various programs that are part of the nsl library and the sockets library. doit.shThis (we may do it in class) just starts up the server, then starts up the client (as we will see, you MUST do it in this order), and then sends a simple query from the client to which the server responds. tcp03.dumpThis is a file captured by the program tcpdump as we will demonstrate (which in turn uses a library program called pcap for capturing network traffic. tcp03.stakThis is the output of a (Java> program of mine called stak which analyzes the various layers of communication involved in running this client and server. Just for kicksYou might browse the contents of the two libraries we use. The Unix command nm is used to learn the names of the programs that are contained in various libraries: So look at what happened when I typed nm libnsl.so.1.txt , and nm libsocket.so.1.txt . These show all the programs (and other things like data sections) that are in the libraries, and from the names you can get an idea of what kinds of things the libraries know how to do. If you are lucky you will never have to look inside one of these again:- |
|
|
Code linksListings
|