cisco数据包跟踪器中的python套接字编程

wsewodh2  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(169)

我正在尝试在cisco数据包跟踪器上运行一个简单的python脚本进行测试。该代码用于打开与客户端的tcp连接的套接字,仅获取字符串,将其设置为大写,并将修改后的字符串发送回客户端。
下面的代码在我的机器上运行良好;但是,当我尝试在cisco数据包跟踪器(服务器上的编程接口)上创建的虚拟服务器上运行此代码时,它返回错误:notimplementederror:socket尚未在第1行的src/lib/socket.py文件中的skulpt中实现

from socket import *
import sys

serverPort = 3125  # Defines the port this socket will be listening

# Opens the socket, AF_INET: IPv4 | SOCK_STREAM: TCP socket

serverSocket = socket(AF_INET, SOCK_STREAM)

# Assigns the serverPort to the server socket

serverSocket.bind(("", serverPort))
serverSocket.listen(1)  # Listens to one connection on the "handshake socket"

print("The server is ready to serve...")  # Prints the server is running

while True:
    # Accepts the connection with the client
    connectionSocket, clientAddress = serverSocket.accept()
    # Receives the messagem from the client
    message = connectionSocket.recv(2048)

    # Closes the server if the message is "exit"
    if message.decode() == "exit":
        connectionSocket.close()
        break

    # Modifies the message to upper case
    modifiedMessage = message.decode().upper()

    # Sends the modified message to the client
    connectionSocket.send(modifiedMessage.encode())
    connectionSocket.close()  # Closes the socket

serverSocket.close()  # Closes the handshake socket
sys.exit()

我很感激。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题