Не удается получить пакеты UDP на Windows 10 из Ubuntu 16.04 - PullRequest
0 голосов
/ 05 марта 2020

Моя Windows (130.203.223.236) и Ubuntu (130.203.223.228) системы находятся в одной сети. Я могу пинговать одно от другого. Я хочу передавать информацию между этими двумя системами, используя UDP. Я могу отправить данные из Windows в Ubuntu, используя следующий код:

Работает на Windows:

# This module provides access to the BSD socket interface. It is available on all modern Unix systems, Windows, Mac OS X, BeOS, OS/2, and probably additional platforms.
import socket

# port details to send data to Ubuntu
send_host = '130.203.223.228'
send_port = 5001

# we made a socket instance and passed it two parameters. The first parameter is AF_INET and the second one is SOCK_DGRAM. AF_INET refers to the address family ipv4. The SOCK_DGRAM means connection oriented UDP protocol. 
send_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

while True:
    send_sock.sendto("Welcome", (send_host, send_port))
    print('Data Sent')

Работает на Ubuntu

# This module provides access to the BSD socket interface. It is available on all modern Unix systems, Windows, Mac OS X, BeOS, OS/2, and probably additional platforms.
import socket

# UDP port details, to receive data from Windows
receive_host = '130.203.223.228'
receive_port = 5001
receive_buffer_size = 1024

# Create socket connection to receive data from Windows
receive_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
receive_sock.bind((receive_host, receive_port))

while True:
    data, addr = receive_sock.recvfrom(receive_buffer_size)
    print('Data Received', data, addr)

Но я не смог отправить данные из Ubuntu в Windows, используя

Работая в Ubuntu:

# This module provides access to the BSD socket interface. It is available on all modern Unix systems, Windows, Mac OS X, BeOS, OS/2, and probably additional platforms.
import socket

# UDP port details, to send data to Windows
send_host = '130.203.223.236'
send_port = 5002

# Create socket connection to send data to Windows
send_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

while True:
    send_sock.sendto("Welcome", (send_host, send_port))
    print('Data Sent')

Запуск на Windows:

# This module provides access to the BSD socket interface. It is available on all modern Unix systems, Windows, Mac OS X, BeOS, OS/2, and probably additional platforms.
import socket

# port details to receive data from Ubuntu
receive_host = '130.203.223.236'
receive_port = 5002
receive_buffer_size = 1024

# we made a socket instance and passed it two parameters. The first parameter is AF_INET and the second one is SOCK_DGRAM. AF_INET refers to the address family ipv4. The SOCK_DGRAM means connection oriented UDP protocol. 
receive_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
receive_sock.bind((receive_host, receive_port))

while True:
    try:
        ego_data, addr = receive_sock.recvfrom(receive_buffer_size)
        print('Data Received', ego_data, addr)
    except socet.error as error:
        print(error)

Нет ошибок при запуске кода

...