Thông tin

Tác giả Vany Ingenzi
Hạn chót Không có hạn chót
Giới hạn nộp bài Không có giới hạn

Tags

Đăng nhập

[Python] Sockets - Creating a socket

In this exercise, you have to create a IPv6 socket, then connect it to the given destination and send a message through the socket.

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 unreliable messages abstractions.

Setting the socket destination is achieved using the connect() call. Use destination address (address, port) that is passed by argument to your function to send a message to the correct destination.

The send() call allows sending a message through the socket.

The message you have to send is the sequence of odd digits as network-ordered integers (int, unsigned integers of 4 bytes) in increasing order. For each of the calls that you use, if one of them were to encounter an error, immediately return -1. All required C headers are already included.

Documentation of interest:


[Python] Sockets - Creating a socket

Copy the function signature and fill in its body

def create_and_send_message(server_addr: str, port: int) -> int:
    # TODO: Create a IPv6 socket supporting datagrams
    # TODO: Connect it to the destination
    # TODO: Send the required message (cfr. statement) through the socket
    pass