Lab 1 CS Majors

Objective

The objective of this lab is to familiarize the student to the development environment on Linux for writing networking code using sockets. This will be done by implementing and testing the code in the later part of the text, Chapter 1.

Method

First, check if your Linux System has g++. Simple type "g++" into a terminal window.

If not there, then execute the following command:

  • sudo apt-get install g++
You will need to enter the login password ("mvnucs" on lab systems).

Create two files, server.cpp and client.cpp. Enter the code as seen in the text. As the code is written it will not compile, as several includes are missing for Linux. I found the following includes to all be needed for client.cpp:

#include <stdio.h>
#include <strings.h>
#include <cstring>
#include <cstdlib>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>

I found the following includes needed for server.cpp:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>

Also, the len variable in server.cpp needs to be of type socklen_t, eg:

socklen_t len;

In addition, you need a single Makefile to to build both of these files. Working Code is found below:

Sample code:

Test out the code between two different systems in the lab, and between the systems in the lab, and the cs.mvnu.edu server (you should have login credentials).

Steps

  1. Go into the "User Accounts" section of Edubuntu, and create a user for yourself. Use this account from now on.
  2. Get the code above running on your lab computer. Add the "g++" application as needed.
  3. By default the client sends messages to a server on the same system, using the address "127.0.0.1". What is the significance of this address? Do some research and explain it in your lab report.
  4. Open up "VMWare" and run the Ubuntu that is in there. Create an account for yourself on that system also. Get the system to work between the outer, and inner operating systems. Do it BOTH way, e.g. with the server on either side. What steps did have to take? What IP addressed did you use? Can you explain the significance of this address?
  5. Get your code to talk to someone elses computer in the lab, in both directions. What steps did you have to take?
  6. Get your code to work between your computer and the cs.mvnu.edu server. You should all have accounts on this system. Again, explain what you had to do.
  7. Note what happens if the server NOT running when you run the Client, nothing happens, no error. Why is this?
  8. Go through the program, and put comments before every line of code, explaining the purpose of that line.

Turn in

  1. (20%) A capture of the working operation.
  2. (30%) The answers to the questions in 3-7.
  3. (30%) The commented code from step 8.
  4. (20%) A paragraph describing your experience, including any difficulties encountered and suggestions for improvement.
-- JimSkon - 2011-09-13
Topic revision: r4 - 2013-11-15 - JimSkon
 
This site is powered by the TWiki collaboration platformCopyright &© by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback