Network sockets (ITI8510)
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 "Hello, Networld!\n\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.
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.