라즈베리파이 UDP 소켓 통신을 실습한다.
[PC]
[udpTx.py]
import socket
host = 'tx.ip.addr.ess'
port = 8080
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind((host, port))
data = b'Hello Raspberry!'
sock.sendto(data, ('rx.ip.addr.ess', port))
sock.close()
[udpRx.py]
import socket
host = 'rx.ip.addr.ess'
port = 8080
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind((host, port))
data = sock.recv(16)
print('Reciived data: {}'.format(data))
print('Received data length: {}'.format(len(data)))
sock.close()
[Test Result]
[참조]
'찐s > Raspberry Pi' 카테고리의 다른 글
[RPi] Lab.04-2: piCamera (0) | 2020.12.06 |
---|---|
[RPi] Lab.04-1: piCamera (0) | 2020.12.05 |
[RPi] Lab.02-3: UART (0) | 2020.11.28 |
[RPi] Lab.02-2: UART (RPi 4B) (0) | 2020.11.22 |