Hi list,
is there a way in pd to send/receive udp packets via sockets?
The problem at hand is to control an Outline ET250-3D turntable from within pd. This turntable can be controlled via udp, which works in principle by using mrpeach's udpsend. Unfortunately, the table responds to a different port every time a udp packet is sent to it, which means that udpreceive and friends will not receive the answer, as they listen to pre-defined ports.
One can however communicate via sockets, i.e. in python, the solution is:
from socket import *
ServerIP = 'xx.xx.xx.xx' Port = 6667 data = bytearray([4, 0, 0, 0]) # command to query table position
client_socket = socket(AF_INET, SOCK_DGRAM)
client_socket.sendto(data, (ServerIP, Port)) recv_data, addr = client_socket.recvfrom(2048) recv_data= [elem.encode("hex") for elem in recv_data]
Is this possible in pd as well? Or, as an alternative, how would one use a python function from within pd to accomplish this?
Thanks, Matthias
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 2013-02-28 14:57, Matthias Blau wrote:
Hi list,
is there a way in pd to send/receive udp packets via sockets?
The problem at hand is to control an Outline ET250-3D turntable from within pd. This turntable can be controlled via udp, which works in principle by using mrpeach's udpsend. Unfortunately, the table responds to a different port every time a udp packet is sent to it, which means that udpreceive and friends will not receive the answer, as they listen to pre-defined ports.
One can however communicate via sockets, i.e. in python, the solution is:
checkout iemnet's [udpclient].
fgmasdr IOhannes
checkout iemnet's [udpclient].
already have tried that - without success. I only get "udpclient:status: sent 4", nothing else.
If I understand it correctly, udpclient listens on the specified port as well, so if the remote udp server gets the request, say on port 6667 and answers on another port (e.g., 60303), how can udpclient receive this answer?
Just to make sure we are talking about the same version: I am on pd-extended 0.43.1 (20120430) under Ubuntu 12.04 64bit.
Matthias
On 02/28/2013 17:33, Matthias Blau wrote:
checkout iemnet's [udpclient].
already have tried that - without success. I only get "udpclient:status: sent 4", nothing else.
If I understand it correctly, udpclient listens on the specified port as well, so if the remote udp server gets the request, say on port 6667 and answers on another port (e.g., 60303), how can udpclient receive this answer?
because you are misunderstanding how udpclient works. each network connection (UDP or TCP/IP) consists of two ports, a sending port and a receiving port. the receiving port (on the server side) is usually fixed, it's the port you connect to. but on the sending side (the client) you also open a port, which is normally chosen randomly from all the currently available ports on the system. this port can be used to get data back from server to client.
[udpsend] will silently discard all data on the sender port, but [udpclient] will not.
Just to make sure we are talking about the same version: I am on pd-extended 0.43.1 (20120430) under Ubuntu 12.04 64bit.
dunno, i have neither. but you can test whether [udpclient] works as expected by doing the following:
netcat to Listen on Udp Port 7777) $ nc -u -l -p 7777
[connect localhost 7777( | [udpclient] | [print foo]
then send something (e.g. "64 64 10") via [udpclient]. you should see whatever you sent appear on the console running netcat, e.g.: @@
now, in the very console running netcat type something "e.g. "foo") and hit return. Pd should print something like "102 111 111 10".
if the iemnet bundled with PdX is broken, you can install the debian packages, by simply running $ sudo aptitude install pd-iemnet
(you might have to go through some hoops to load and use the correct iemnet in PdX, but this is mere speculation on my side)
gasdmr IOhannes
On Fre, 2013-03-01 at 08:53 +0100, IOhannes m zmölnig wrote:
On 02/28/2013 17:33, Matthias Blau wrote:
checkout iemnet's [udpclient].
already have tried that - without success. I only get "udpclient:status: sent 4", nothing else.
If I understand it correctly, udpclient listens on the specified port as well, so if the remote udp server gets the request, say on port 6667 and answers on another port (e.g., 60303), how can udpclient receive this answer?
because you are misunderstanding how udpclient works. each network connection (UDP or TCP/IP) consists of two ports, a sending port and a receiving port. the receiving port (on the server side) is usually fixed, it's the port you connect to. but on the sending side (the client) you also open a port, which is normally chosen randomly from all the currently available ports on the system. this port can be used to get data back from server to client.
[udpsend] will silently discard all data on the sender port, but [udpclient] will not.
Just to make sure we are talking about the same version: I am on pd-extended 0.43.1 (20120430) under Ubuntu 12.04 64bit.
dunno, i have neither. but you can test whether [udpclient] works as expected by doing the following:
- run a simple udp-server from the commandline (the following uses
netcat to Listen on Udp Port 7777) $ nc -u -l -p 7777
- start Pd (in another terminal), load iemnet, and do
[connect localhost 7777( | [udpclient] | [print foo]
then send something (e.g. "64 64 10") via [udpclient]. you should see whatever you sent appear on the console running netcat, e.g.: @@
now, in the very console running netcat type something "e.g. "foo") and hit return. Pd should print something like "102 111 111 10".
if the iemnet bundled with PdX is broken, you can install the debian packages, by simply running $ sudo aptitude install pd-iemnet
Why are you assuming it is broken in Pd-extended?
Actually, it seems to have glitches. With above setup, right after connecting [udpclient] to the netcat server, you cannot send anything from netcat to the client. Only after sending at least one packet from [udpclient], it flushes all messages it has received from the server since the connection. From this point in time, the communication works instantly both ways.
This is on Linux (Ubuntu 12.04) with most recent iemnet and Pd compiled from source, but also with Pd-0.43.3-extended.
When using netcat as UDP client, I can start sending packets from the server immediately.
Roman
On 03/01/2013 01:15 PM, Roman Haefeli wrote:
Why are you assuming it is broken in Pd-extended?
i'm not. matthias said that it didn't work. i was offering possible reasons (wrong usage, broken binaries), and how to fix them. i hope (and am pretty confident), that the PdX binaries work.
Actually, it seems to have glitches. With above setup, right after connecting [udpclient] to the netcat server, you cannot send anything from netcat to the client. Only after sending at least one packet from [udpclient], it flushes all messages it has received from the server since the connection. From this point in time, the communication works instantly both ways.
This is on Linux (Ubuntu 12.04) with most recent iemnet and Pd compiled from source, but also with Pd-0.43.3-extended.
When using netcat as UDP client, I can start sending packets from the server immediately.
are you sure? because i cannot. i get exactly the behaviour you just described, but when using netcat as both client and server.
fgasrdmn IOhannes
On Fri, 2013-03-01 at 13:38 +0100, IOhannes zmölnig wrote:
On 03/01/2013 01:15 PM, Roman Haefeli wrote:
Actually, it seems to have glitches. With above setup, right after connecting [udpclient] to the netcat server, you cannot send anything from netcat to the client. Only after sending at least one packet from [udpclient], it flushes all messages it has received from the server since the connection. From this point in time, the communication works instantly both ways.
This is on Linux (Ubuntu 12.04) with most recent iemnet and Pd compiled from source, but also with Pd-0.43.3-extended.
When using netcat as UDP client, I can start sending packets from the server immediately.
are you sure? because i cannot. i get exactly the behaviour you just described, but when using netcat as both client and server.
After re-checking, I confirm what you say. I must have mixed up client and server when testing the first time. Which means: [iemnet/udpclient] works as expected. After thinking about it, it is clear that the server cannot know which clients are connected until they actually send something, since there is no connection handshake involved.
Roman
You can also try disis_netsend/receive which is nearly identical to Pd's netsend/receive, except that it provides additional features including UDP broadcast, msg queueing etc., including a different way for dispatching received messages that has (at least on pd-l2ork) solved freezing gui issues. On Mar 1, 2013 7:16 AM, "Roman Haefeli" reduzent@gmail.com wrote:
On Fre, 2013-03-01 at 08:53 +0100, IOhannes m zmölnig wrote:
On 02/28/2013 17:33, Matthias Blau wrote:
checkout iemnet's [udpclient].
already have tried that - without success. I only get "udpclient:status: sent 4", nothing else.
If I understand it correctly, udpclient listens on the specified port
as
well, so if the remote udp server gets the request, say on port 6667
and
answers on another port (e.g., 60303), how can udpclient receive this answer?
because you are misunderstanding how udpclient works. each network connection (UDP or TCP/IP) consists of two ports, a sending port and a receiving port. the receiving port (on the server side) is usually fixed, it's the port you connect to. but on the sending side (the client) you also open a port, which is normally chosen randomly from all the currently available ports on the system. this port can be used to get data back from server to client.
[udpsend] will silently discard all data on the sender port, but [udpclient] will not.
Just to make sure we are talking about the same version: I am on pd-extended 0.43.1 (20120430) under Ubuntu 12.04 64bit.
dunno, i have neither. but you can test whether [udpclient] works as expected by doing the following:
- run a simple udp-server from the commandline (the following uses
netcat to Listen on Udp Port 7777) $ nc -u -l -p 7777
- start Pd (in another terminal), load iemnet, and do
[connect localhost 7777( | [udpclient] | [print foo]
then send something (e.g. "64 64 10") via [udpclient]. you should see whatever you sent appear on the console running netcat,
e.g.:
@@
now, in the very console running netcat type something "e.g. "foo") and hit return. Pd should print something like "102 111 111 10".
if the iemnet bundled with PdX is broken, you can install the debian packages, by simply running $ sudo aptitude install pd-iemnet
Why are you assuming it is broken in Pd-extended?
Actually, it seems to have glitches. With above setup, right after connecting [udpclient] to the netcat server, you cannot send anything from netcat to the client. Only after sending at least one packet from [udpclient], it flushes all messages it has received from the server since the connection. From this point in time, the communication works instantly both ways.
This is on Linux (Ubuntu 12.04) with most recent iemnet and Pd compiled from source, but also with Pd-0.43.3-extended.
When using netcat as UDP client, I can start sending packets from the server immediately.
Roman
Pd-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
On 03/01/2013 01:44 PM, Ivica Bukvic wrote:
You can also try disis_netsend/receive which is nearly identical to Pd's netsend/receive, except that it provides additional features including UDP broadcast, msg queueing etc., including a different way for dispatching received messages that has (at least on pd-l2ork) solved freezing gui issues.
does it allow bidirectional communication via UDP? because afaict, that was what the original question was about...
fsamdrt IOhannes
Sorry, missed that part. Not via a single object. Yes, when using both send and receive objects. On Mar 1, 2013 8:00 AM, "IOhannes zmölnig" zmoelnig@iem.at wrote:
On 03/01/2013 01:44 PM, Ivica Bukvic wrote:
You can also try disis_netsend/receive which is nearly identical to Pd's netsend/receive, except that it provides additional features including UDP broadcast, msg queueing etc., including a different way for dispatching received messages that has (at least on pd-l2ork) solved freezing gui issues.
does it allow bidirectional communication via UDP? because afaict, that was what the original question was about...
fsamdrt IOhannes
______________________________**_________________ Pd-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/** listinfo/pd-list http://lists.puredata.info/listinfo/pd-list
On 03/01/2013 02:04 PM, Ivica Bukvic wrote:
Sorry, missed that part. Not via a single object. Yes, when using both send and receive objects.
that's interesting. or do you mean, that you can open two uni-directional UDP connections rather than one bi-directional UDP-connection? because this won't work, if the peer requests a single bi-directional communication channel, which i think this device does (and which is quite common outside Pd)
fgmasdr IOhannes
I meant two unidirectional connections--apologies for the noise...
-----Original Message----- From: pd-list-bounces@iem.at [mailto:pd-list-bounces@iem.at] On Behalf Of IOhannes zmölnig Sent: Friday, March 01, 2013 8:08 AM To: pd-list Subject: Re: [PD] create/access udp sockets from within pd
On 03/01/2013 02:04 PM, Ivica Bukvic wrote:
Sorry, missed that part. Not via a single object. Yes, when using both
send
and receive objects.
that's interesting. or do you mean, that you can open two uni-directional UDP connections rather than one bi-directional UDP-connection? because this won't work, if the peer requests a single bi-directional communication channel, which i think this device does (and which is quite common outside Pd)
fgmasdr IOhannes
Pd-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
but you can test whether [udpclient] works as expected by doing the following:
- run a simple udp-server from the commandline (the following uses
netcat to Listen on Udp Port 7777) $ nc -u -l -p 7777
- start Pd (in another terminal), load iemnet, and do
[connect localhost 7777( | [udpclient] | [print foo]
then send something (e.g. "64 64 10") via [udpclient]. you should see whatever you sent appear on the console running netcat, e.g.: @@
now, in the very console running netcat type something "e.g. "foo") and hit return. Pd should print something like "102 111 111 10".
Well, that works perfectly. Unfortunately, it doesn't work for the Outline turntable, whereas the python snippet I sent with my first email does. Also, iemnet objects in Pd-extended (even the help files) under WinXP crash pd.
So, at the moment, I use the shell object to execute a python script every time I want to know the table position (this is the most important information from the table). Not too elegant, but it works.
Any better ideas?
Thanks again, Matthias