Aswin Murugesh
Aswin Murugesh

Reputation: 11070

Send additional arguments through socket.sendto()

I am new to networking using python. I was working with the socket.sendto() function. I want to know if more arguments can be sent through the function, along with the message string, like as in a timestamp. I just added a variable to the sendto function. but that throws TypeError: Integer required. Why is it so? How can I send an additional argument?

Upvotes: 1

Views: 2427

Answers (1)

Blender
Blender

Reputation: 298246

I want to know if more arguments can be sent through the function

Look at the documentation:

socket.sendto(string, address)

socket.sendto(string, flags, address)

Send data to the socket. The socket should not be connected to a remote socket, since the destination socket is specified by address. The optional flags argument has the same meaning as for recv() above. Return the number of bytes sent. (The format of address depends on the address family — see above.)

socket isn't a high-level interface; you send bytes and receive bytes. All of the data that you want to send should be encoded in the string argument and get decoded on the receiving side.

Upvotes: 2

Related Questions