python - 通过 socket.sendto() 发送附加参数

标签 python sockets networking

我是使用 python 进行网络连接的新手。我正在使用 socket.sendto() 函数。我想知道是否可以通过该函数发送更多参数以及消息字符串,就像在时间戳中一样。我刚刚向 sendto 函数添加了一个变量。但这会抛出TypeError: Integer required。为什么会这样呢?我如何发送附加参数?

最佳答案

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

看看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 不是一个高级接口(interface);您发送字节并接收字节。您要发送的所有数据都应在 string 参数中进行编码,并在接收端进行解码。

关于python - 通过 socket.sendto() 发送附加参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18669064/

相关文章:

python - ValueError : logits and labels must have the same shape ((None, 14)与(无,1))

python - 更好的 Python 包管理器

java - 从尚未关闭的服务器套接字读取所有字符串

Python socket.recv 异常

Java 网络序列化在可序列化对象上失败

python - 如何检查用户输入的姓名?

python - NDB .order 返回空结果

java - 在多线程环境中限制连接组的速率

ios - 获取所有可用 Wifi 连接的列表并选择一个连接到 iOS 11 中的应用程序内

python - 如何在 Linux 中找到开放端口?