$ nc -u -l 2399 (in windows cmd console in order to listen)$ nc -u 192.168.1.5 2399 (in Raspberry Shake, via putty, in order to send a Hello message)HelloResult: No message arrives to my command line of windows laptop.
Case 2. Executing \opt\settings\user\shake-UDP-remote.py as you can see
import socket as shost = "192.168.1.35" #when running not on the Shake Pi: blank = localhostport = 18002 # Port to bind toHP = host + ":" + str(port)print " Opening socket on (HOST:PORT)", HPsock = s.socket(s.AF_INET, s.SOCK_DGRAM | s.SO_REUSEADDR)sock.bind((host, port))print "Waiting for data on (HOST:PORT) ", HPwhile 1: # loop foreverdata, addr = sock.recvfrom(1024) # wait to receive dataprint data
Result:
Opening socket on (HOST:PORT) 192.168.1.35:18002Traceback (most recent call last):File "shake-UDP-remote.py", line 10, in <module>sock.bind((host, port))File "/usr/lib/python2.7/socket.py", line 224, in methreturn getattr(self._sock,name)(*args)socket.error: [Errno 99] Cannot assign requested address
{"UDP-destinations" : [{ "dest" : "UDP-1"},{ "dest" : "UDP-2"}],"UDP-1" : {"Hostname" : "UDPIPFILE:/opt/settings/sys/ip.txt","Port" : "8888"},"UDP-2" : {"Hostname" : "192.168.1.35","Port" : "18002"}}
Result: In debug Node UDP
21/10/2018 23:22:21node: 4ea77c9d.6756e4msg : string[25]"udp: port already in use"
import socket as s
host = "" # blank = localhost (you are on the receiving end)
port = 18002 # port the Shake sends data to
HP = host + ":" + str(port)
print " Opening socket on (HOST:PORT)", HP
sock = s.socket(s.AF_INET, s.SOCK_DGRAM | s.SO_REUSEADDR)
sock.bind((host, port))
print "Waiting for data on (HOST:PORT) ", HP
while 1: # loop forever
data, addr = sock.recvfrom(1024) # wait to receive data
print data
{
"UDP-destinations" : [
{ "dest" : "YOURCOMPUTER"}
],
"YOURCOMPUTER" : {
"Hostname" : "192.168.1.5",
"Port" : "18002"
}
}
Both computers (RpiShake and laptop) are in the same network (home) connected to a router by dongle wifi.
Your answer clarify some wrong ideas, I have, but after I execute (in spyder on anaconda with python 3.6) your code recommendation it appear another error; similar to reported in “Plotting UDP data live” thread By Graham. “OSError: [WinError 10044] The support for the specified socket type does not exist in this address family”, but in Spanish (OSError: [WinError 10044] No existe compatibilidad para el tipo de socket especificado en esta familia de direcciones).
Then I tested to execute Richard code recommendation to Graham (below), but I don’t detect any data sended (“Hello, World”) in Terminal IPython of receiver.
code to receive UDP data
==== BEGIN CODE SNIPPET ====
import socket
UDP_IP = "127.0.0.1"
UDP_PORT = 5005
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))
while True:
data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
print "received message:", data
==== END CODE SNIPPET ====
and the code to send a UDP message:
==== BEGIN CODE SNIPPET ====
import socket
UDP_IP = "127.0.0.1"
UDP_PORT = 5005
MESSAGE = "Hello, World!"
print "UDP target IP:", UDP_IP
print "UDP target port:", UDP_PORT
print "message:", MESSAGE
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
==== END CODE SNIPPET ====
I´ll try to test other possibilities, I studied carefully 3 threads related with this subject and manual.(Accessing data on Shake, Plotting UDP data live and
· Raw data Access)
Any other Idea to test?
Regards.
import socket
UDP_IP = "127.0.0.1" # localhost
UDP_PORT = 5005
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))
while True:
data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
print("received message:", data)import socket
UDP_IP = "127.0.0.1"
UDP_PORT = 5005
MESSAGE = b"Hello world"
print("UDP target IP:", UDP_IP)
print("UDP target port:", UDP_PORT)
print("message:", MESSAGE)
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))--
Some useful links:
Manual: http://manual.raspberryshake.org/
Do It YourSelf Page: http://raspberryshake.org/do-it-yourself
Shop: https://shop.raspberryshake.org/
Website: http://raspberryshake.org/
Instagram: https://www.instagram.com/raspishake/
Facebook: https://www.facebook.com/raspishake/
Twitter: https://twitter.com/raspishake/
Hashtag: #rasperryshake, @raspishake
DOI: https://doi.org/10.7914/SN/AM
---
You received this message because you are subscribed to the Google Groups "RaspberryShake" group.
To unsubscribe from this group and stop receiving emails from it, send an email to raspberryshak...@googlegroups.com.
To post to this group, send email to raspber...@googlegroups.com.
Visit this group at https://groups.google.com/group/raspberryshake.
To view this discussion on the web visit https://groups.google.com/d/msgid/raspberryshake/de983df9-2405-4388-98f0-9a83c956aa05%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.