Información

Fecha de entrega Sin fecha de envío
Tiempo límite de envío Sin límite de envío

Etiquetas

Inicia sesión

[Python] Sockets - Creating a listening socket

In this exercise, you have to create a IPv6 socket, set it to listening mode and read an incoming message. Then you have to perform some computation using the received message and send back the result to the message sender.

To create the socket, you have to use the socket() call and provide it with the correct parameters. Make sure to configure it for the IPv6 domain and set its type to support datagrams. Datagrams are simple messages abstractions.

Setting the socket to listen for incoming messages is achieved using the bind() call.

The recv() call allows waiting for the reception of a message, it returns the message and the associated sender address. A 1024-byte buffer should be sufficient to hold a message.

The message you will receive is a sequence of numbers (uint32, unsigned integers of 4 bytes) that are network-ordered integers. You have to sum all the numbers and send the result back to the message sender in network order. Use sendto() to send back the result.

For each of the calls that you use, if one of them were to encounter an error, immediately return -1.

Documentation of interest:


[Python] Socket - Creating a listening socket

Copy the function signature and fill in its body

def recv_and_handle_message(bind_addr: str, bind_port: int) -> int:
    # TODO: Create a IPv6 socket supporting datagrams
    # TODO: Bind it to the source
    # TODO: Receive a message through the socket
    # TODO: Perform the computation
    # TODO: Send back the result
    return 0