lab1 - CSE 422 Spring 2008 Lab 1 Simple log-in and connect...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE 422 Spring 2008 Lab 1: Simple log-in and connect client and server Objective: This lab will introduce you to socket programming using both UDP and TCP connections. You will create both a client and the server program. The client will send a username and password using UDP to the server, which will check them against stored values and if they match will respond with a TCP port that the server is listening on. If the port is returned, then the client will create a TCP connection to the server. Follow the steps to begin this lab. At the end there will be tasks for you to complete. Note: You must run and compile these applications using Linux. adriatic.cse.msu.edu is a Linux based server and there are about 15 Linux machines in the Simpson Lab (3353). We strongly suggest trying to find a way to use two different computers for the client and server, but using localhost for the server address will work if you are using the same machine to run both client and server (by opening two terminals). If you are using two different machines in the Simpson Lab, they can be addressed by the computer name listed on the machine and on each line of the terminal. Note: If you have binding errors it is likely that the port you are using is already bound by another application and you should use a different port number. Step1: Download or copy the files in the folder ~cse422b/web/ss08/lab1/files. There should be four files: server.cc, client.cc, packet.h, and makefile. Server.cc and client.cc are simple skeletons and only contain empty main functions that should compile using the make command. Step2: Creating the UDP socket client side (client.cc) In order to create the UDP socket we are going to need two pieces of information. The first is the server’s domain name and second the port it will listen on. To make the program dynamic, we are going to pass in these values through the command line, in the form client <hostname> <udp_port>. To make sure the user enters these values, we are going to make sure the command line contains 3 elements. The following lines are what are needed for the program: if ( argc != 3 ) { cout << " Usage: " << argv[0] << " <hostname> <udp_port>" << endl; exit(0); } const char * server_host = argv[1]; unsigned short server_port = ( short ) atoi(argv[2]); Now we need to create a socket and store its descriptor. int udp_fd; // socket descriptor
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
// create the socket if ( (udp_fd = socket(AF_INET,SOCK_DGRAM,0)) < 0 ) { cerr << "udp error!" << endl; exit(0); } Finally we need to store in the server’s address in an object the network client can understand.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern