hw1sol - CSCI 415 Computer Networks Homework 1 Solution...

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

View Full Document Right Arrow Icon
CSCI 415 Computer Networks Homework 1 Solution Saad Mneimneh Computer Science Hunter College of CUNY Problem 1 Listen to the first movement of Beethoven’s fifth symphony. ANSWER : Problem 2 Write the following sentence in Morse code: “I am in the CSCI 415 class.” ANSWER : .. .- -- .. -. - .... . -.-. ... -.-. .. .... - .---- . .... -.-. .-. . .- . .. ... Problem 3 Compile the following server and client C++ code and run it. You will be asked to modify the code in a later homework. server.c #include <iostream> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <unistd.h> using std::cout; using std::cin; const unsigned short int port = 5432; const int max_pending = 10; const int max_len = 256;
Background image of page 1

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

View Full DocumentRight Arrow Icon
int main() { sockaddr_in address; //address sockaddr_in client_address; //client address char message[max_len]; int s; int new_s; int len; //build address memset(&address, 0, sizeof(address)); address.sin_family = AF_INET; address.sin_addr.s_addr = htonl(INADDR_ANY); address.sin_port = htons(port); //setup passive open if ((s=socket(PF_INET, SOCK_STREAM, 0)) < 0) { cout<<"error in socket"; return 0; } //bind socket to address cout<<"error in bind"; return 0; } if (listen(s, max_pending) < 0) { cout<<"error in listen"; return 0; } //wait for connection, then receive message
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.

This note was uploaded on 03/27/2010 for the course CSCI 415 taught by Professor Saadmneimneh during the Spring '08 term at CUNY Hunter.

Page1 / 4

hw1sol - CSCI 415 Computer Networks Homework 1 Solution...

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