我正在构建一个简单的UDP客户端,但是,我收到一条错误消息“套接字不可调用”。我已经检查了代码,它可以找到问题
我尝试使用“ from socket import *”来导入模块,但是没有用。
import socket
serverName = 'hostname'
serverPort = 1200
clientSocket = socket(socket.AF_INET, socket.SOCK_DGRAM)
message = 'Testing the system'
clientSocket.sendto(message, (serverName, serverPort))
modifiedMessage, serverAddress = clientSocket.recvfrom(2048)
print(modifiedMessage)
clientSocket.close()
答案 0 :(得分:1)
您需要像这样从套接字模块导入套接字
import socket
from socket import socket as sk
serverName = 'hostname'
serverPort = 1200
clientSocket = sk(socket.AF_INET, socket.SOCK_DGRAM)
等
答案 1 :(得分:0)
我认为您已将程序命名为socket.py
或将程序存储在包含socket.py
的文件夹中。重命名文件或删除文件
答案 2 :(得分:0)
您的代码应该可以工作,您只需要更改
data = load_iris()
df = pd.DataFrame(data["data"], columns=data["feature_names"])
df["class"] = data["target"]
# Create scaler outside the class
scaler = SklearnWrapper(StandardScaler())
# Fit and transform data (holding state)
df_rescaled = df.groupby("class").apply(scaler.fit_transform)
# Inverse the operation
df_inverted = df_rescaled.groupby("class").apply(scaler.inverse_transform)
# Apply transformation once again
df_transformed = (
df_inverted.groupby("class")
.apply(scaler.transform)
.drop("class", axis="columns")
)
收件人
clientSocket = socket(socket.AF_INET, socket.SOCK_DGRAM)
您正在尝试将输入而不是模块内部功能(clientSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
)馈送到模块(socket
)