Socket Client

Job ID: 35460046

Budget: $30 – $250 USD

Create a program that accepts a list of host names on the command line. For example

./a.out xlp.net yahoo.com slashdot.net

for each address, a child is spawned that attempts to connect to that address on port 80, and sends

"GET / HTTP/1.1\r\nHost: <address from argv> \r\nConnection: close\r\n\r\n"
through the socket. If it receives data in response (reading the socket results in more than 0 bytes read) it ends with return code 0, otherwise it returns -1.

The parent waits for all processes to end then prints the total number of children that returned 0.

Sample run:

> ./a.out xlp.net

String received from the server:
HTTP/1.1 302 Found
Cache-Control: no-cache
Content-length: 0
Location: https://xlp.net
Connection: close
Count: 1