【发布时间】:2020-06-11 18:44:09
【问题描述】:
我正在尝试根据我正在学习的课程编写一个非常简单的“网络套接字”(服务器)程序和“网络连接”(客户端)程序。我在尝试使用来自 VMWare Workstation 15 中 Kali Linux 虚拟机的“网络连接”程序进行连接时收到 [WinError 10053]。Kali VM 网络适配器正在 NAT 模式下运行。
服务器
import socket
SRV_ADDR = input("Type the server IP address: ")
SRV_PORT = int(input("Type the server port: "))
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((SRV_ADDR, SRV_PORT))
s.listen(1)
print("Server started! Waiting for connections...")
connection, address = s.accept()
print('Client connected with address:', address)
while 1:
data = connection.recv(1024)
if not data: break
connection.sendall(b'-- Message Received --\n')
print(data.decode('utf-8'))
connection.close()
客户
import socket
SER_ADDR = input("Type the server IP address: ")
SER_PORT = int(input("Type the server port: "))
s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s2.connect((SER_ADDR, SER_PORT))
print("Connection Established")
message = input("Message to send: ")
s2.sendall(message.encode())
s2.close()
当我从本地计算机运行“网络套接字”程序时,我可以使用 Netcat 从 Kali VM 成功连接,并发送数据。
如果我尝试从 Kali 运行“网络连接”程序,我会成功连接,但是当我发送数据时,我会收到 WinError 10053 和“网络连接”程序中对第 13 行的引用。
任何帮助将不胜感激。抱歉,如果没有正确发布,这是我第一次在论坛上发帖:)
【问题讨论】:
标签: python sockets networking virtual-machine