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

Info iconThis 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
Background image of page 1

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

View Full DocumentRight 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. sockaddr_in
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 7

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

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online