Network Sockets (ITS8020)

Allikas: Kursused
Redaktsioon seisuga 16. november 2018, kell 09:39 kasutajalt Irve (arutelu | kaastöö) (Uus lehekülg: '''The goal is to try sending and receiving data over the socket interface'' You will use socket(), connect(), bind(), listen(), accept() and socket addresses for the task. ==Ta...')
(erin) ←Vanem redaktsioon | Viimane redaktsiooni (erin) | Uuem redaktsioon→ (erin)
Mine navigeerimisribale Mine otsikasti

The goal is to try sending and receiving data over the socket interface

You will use socket(), connect(), bind(), listen(), accept() and socket addresses for the task.

Task

There are two separate tasks.

Connection

Write a program which tries connecting to a specified machine on specified port so the following command:

connect www.lambda.ee 80

would connect to www.lambda.ee on port 80. Write

GET http://courses.cs.ttu.ee/pages/Esileht/ HTTP/1.0\r\n\r\n

to the socket and display any resulting data on screen. Terminate when connection is closed.

Listening

Write a server program which shows on screen whatever data is received from the network. The command line:

listen 3333

would listen on port 3333 and display any received connections.

When connection is made, display the address of the other connection, then display the data until connection is closed.

Bonus

If the former part of the exercises does not provide you with sufficient brain-stimulation. Please try the following: Create a program which outputs the output of "ls -l" to the network on the given socket when connected; using dup() or dup2() functions. For running a progam you could use fork() and execv(). It could work as follows:

lsner 3333

And then you could try it out using netcat for example.

Tips

Use netcat for connecting and listening to your program:

nc www.lambda.ee 80
nc -l 8080

Note that you can only listen to ports starting from 1024. In addition to that, the Dijkstra server has an external firewall which prevents connections from outside unless you listen on ports 7400-8000 .