2015-09-07 07:28:02 -04:00
|
|
|
import socket
|
|
|
|
import threading
|
|
|
|
|
|
|
|
|
|
|
|
def test(fpga_ip, udp_port, test_message):
|
|
|
|
tx_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
|
|
rx_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
|
|
rx_sock.bind(("", udp_port))
|
|
|
|
rx_sock.settimeout(0.5)
|
|
|
|
|
|
|
|
def receive():
|
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
msg = rx_sock.recv(8192)
|
|
|
|
for byte in msg:
|
|
|
|
print(chr(byte), end="")
|
|
|
|
except:
|
|
|
|
break
|
|
|
|
|
|
|
|
def send():
|
|
|
|
tx_sock.sendto(bytes(test_message, "utf-8"), (fpga_ip, udp_port))
|
|
|
|
|
|
|
|
receive_thread = threading.Thread(target=receive)
|
|
|
|
receive_thread.start()
|
|
|
|
|
|
|
|
send_thread = threading.Thread(target=send)
|
|
|
|
send_thread.start()
|
|
|
|
|
|
|
|
try:
|
|
|
|
send_thread.join(5)
|
|
|
|
send_thread.join(5)
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2015-11-16 18:16:39 -05:00
|
|
|
# # #
|
|
|
|
|
|
|
|
test_message = "LiteEth virtual TTY Hello world\n"
|
2016-03-15 10:40:06 -04:00
|
|
|
test("192.168.1.50", 10000, test_message)
|
2015-11-16 18:16:39 -05:00
|
|
|
|
|
|
|
# # #
|