Я строю сценарий в симуляторе Mininet SDN с использованием Ubuntu 18.
Приложения, встроенные в хосты в сценарии, представляют собой простой чат клиент-сервер, написанный на python.Следующий код Python клиента-сервера:
Код клиента:
#!/usr/bin/python3
import socket
import sys
#Create socket object
clientsocket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
host = str(sys.argv[1])
port = int(sys.argv[2])
clientsocket.connect((host, port)) #You can substitue the host with the
server IP
while True:
message = input('Enter your message: ')
clientsocket.send(message.encode())
print('Receiving...')
#Receiving a maximum of 1024 bytes
message = clientsocket.recv(1024)
print('Message received: ', message.decode('ascii'))
clientsocket.close()
Код сервера:
#!/usr/bin/python3
import socket
import sys
#Creating the socket object
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = socket.gethostname() #Host is the server IP
port = int(sys.argv[1]) #Port to listen on
#Binding to socket
serversocket.bind(("0.0.0.0", port)) #Host will be replaced/substitued with IP, if changed and not running on host
#Starting TCP listener
serversocket.listen(3)
while True:
#Starting the connection
clientsocket,address = serversocket.accept()
print("Received connection from ", str(address))
while True:
message = clientsocket.recv(1024)
print('Message received: ', message.decode('ascii'))
#Message sent to client after successful connection
message = input('Enter your reply: ')
clientsocket.send(message.encode())
clientsocket.close()
Когда я пытаюсь выполнить эти коды вПосле запуска сценария XTerm возникает следующая ошибка:
Traceback (most recent call last):
File "TCPClient.py", line 13, in <module>
clientsocket.connect((host, port)) #You can substitue the host with the server IP
OSError: [Errno 113] No route to host
Что мне делать?