project 2

7
Project 2 Data Communication Spring 2010, ICE 3025-44 Stephen Kim, Ph.D.

Upload: marsden-reese

Post on 30-Dec-2015

25 views

Category:

Documents


0 download

DESCRIPTION

Project 2. Data Communication Spring 2010, ICE 3025-44 Stephen Kim, Ph.D. Due Date. April 9th, 2010. Mission. You will modify the previous project to make the server to handle multiple connections simultaneously. Echo Server - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Project  2

Project 2Data Communication

Spring 2010, ICE 3025-44Stephen Kim, Ph.D.

Page 2: Project  2

Due DateApril 9th, 2010

Page 3: Project  2

MissionYou will modify the previous project to make the

server to handle multiple connections simultaneously. Echo Server

◦ The server uses a thread library. On a successful connection, the accept() function returns a new socket. You create a new thread with a communication function, and the new socket and the client address are passed to the communication function that communicate with a client until it receive an empty message.

◦ The child thread, or the communication function, receives a message from the client and print the client’s IP address and optionally the client’s port number followed by the message, repeatedly. For example, 115.145.203.30:4874 > Hello. World!

◦ The parent thread waits for another connection with the accept() function.

Page 4: Project  2

Echo Client◦ The previous client reads only one line from the keyboard. This

short-lived execution is improper to demonstrate multiple connections at the server side.

◦ You modifies the client to repeat the process of reading keyboard, sending, receiving, printing until a user enters an empty line. Be aware that the client sends the empty line to the server so that the server recognize the end of connection to close it properly.

◦ The client shows the source of a message by using a keyboard prompt, and the server’s IP address and optionally the server’s port number followed by the message, repeatedly. For example, KEYBORD > Hello. World!142.35.203.30:3000 > Hello. World!

Empty message◦ Each message is terminated by a new line character, LF, CR, or

CR/LF depending OS. ◦ An empty message is a message containing no user message but

the new line character.

Page 5: Project  2

TeamYou will form a group of 5 persons. Each group submits ONE copy of the project

report, but each member completes a “Peer Rating” form and submits it to the instructor CONFIDENTIALLY.

Page 6: Project  2

RequirementThe project description must be properly

demonstrated in the project report. Use either C or C++ programming language.

Period. The submission must include soft and hard copy of

◦ source files (C files and H files) ◦ text trace of compilation◦ text trace of execution (the client side, and the server side)

All codes must be properly formatted and tabbed, and include proper in-line documents (comments).

All submission must be archived (compressed) into a single file for submission of soft copy.  

Page 7: Project  2

Tips for POSIX Thread Pthread tutorials and resources

◦ http://en.wikipedia.org/wiki/POSIX_Threads

◦ http://ko.wikipedia.org/wiki/POSIX_쓰레드

#include <pthread.h>#include <stdio.h>#include <stdlib.h>#define NUM 5

void *PrintHello(void *threadid) { long tid; tid = (long)threadid; printf(“Thread #%ld!\n", tid); pthread_exit(NULL); }

int main (int argc, char *argv[]) { pthread_t threads[NUM]; int rc; long t; for(t=0; t<NUM; t++){ rc = pthread_create(&threads[t], NULL, PrintHello,(void *)t); if (rc) { fprintf(stderr, "ERROR;%d\n“,rc); exit(-1); } } pthread_exit(NULL); }