Forums > MaxMSP

sending raw bytes with net.udp.send


May 10, 2006 | 5:26 am

Hi peoples!

I’m hoping to use net.udp.send (or a varient thereof) to send raw
bytes over a local network. Unfortuantely, the receiving hardware
can’t decode the datagram packets it currently spits out.

I’ve seen some threads about getting net.udp.recv to get bytes, but
nothing on sending.

My java skills are fairly ruimentary, so any advice or pointers on how
to get this up and running would be great.

thanks,

~scott

May 10, 2006 | 11:33 am

hi scott!

last year i was attempting this w/ a friend in order to control some
ColorKinetics lights. our engineer friend at ColorKinetics ended up
hacking the receiving hardware before i got to making the needed
external (and sadly he passed away last fall).

sorry i can’t be more helpful, but here are some good links i came
across in my research:

http://java.sun.com/docs/books/tutorial/networking/datagrams /index.html
http://java.sun.com/docs/books/tutorial/networking/TOC.html
http://java.sun.com/j2se/1.5.0/docs/api/java/net/DatagramSoc ket.html
http://java.sun.com/j2se/1.5.0/docs/api/java/net/DatagramPac ket.html

http://www.codeguru.com/java/tij/tij0166.shtml
http://homepages.uel.ac.uk/2795l/pages/javaapps.htm
http://www.javaworld.com/javaworld/javatips/jw-javatip40.htm l

hope that helps! :)

best,
joanthan

May 10, 2006 | 12:24 pm

ha! that’s the exact thing i’m looking to do.

previously i’ve used Masayuki Akamatsu’s aka.datagram to send the
bytes, but now i’m working on either macintel or windows. the
performance is there under osx, but i’m afraid to push it too much
under emulation.

i also figured, why not get some more java working. (the prebuilt
objects work brilliantly for local networks)

thanks for the links, i’ll poke through them and let you know what i
come up with!

~s

May 10, 2006 | 12:45 pm

really! you got aka.datagram to work with CK lights? that’s great :)
is your method/patch something you’d be willing to share?

good luck with the java hacking

j

May 10, 2006 | 1:10 pm

hi,
here is some more to poke around.
i’m no java guru at all, but i use the code snippet below
successfully in an installation to send raw bytes over udp. it’s
pretty much the same as for receiving raw bytes. just make sure to
convert the input (in my case a string) to bytes.
hth,
volker.

public void send(String s) {
int packSize = s.length();
DatagramSocket sock;
byte[] buffer = new byte[packSize]; // allocate data buffer

//convert message to bytes and fill buffer
for(int i=0; i

buffer[i] = (byte)s.charAt(i);

try {
servAddr = InetAddress.getByName(host);
sock = new DatagramSocket();
post("packet sent");
// create UDP-Packet to send
DatagramPacket packet = new DatagramPacket(buffer, packSize,
servAddr, port);
// send the packet
sock.send(packet);
sock.disconnect();
}
catch(IOException e) {
System.err.println(e);
}

}

May 10, 2006 | 1:17 pm

i did something like this a while ago, using aka.datagram

see forum for demo patch:

< http://www.cycling74.com/forums/index.php?
t=msg&goto=33697&rid=0&S=696731e1d094c2b91b00c8a 9532d31ff&sr ch=rekveld+u
dp+patch#msg_33697>

ciao,

Joost.

——————————————-

Joost Rekveld
———–
http://www.lumen.nu/rekveld

——————————————-

"The mystery of the world is the visible, not the invisible"
(Oscar Wilde)

——————————————-

May 10, 2006 | 1:20 pm

sweet! thanks.

February 16, 2008 | 2:14 am

Hi Volker, I’m trying to use your code to do exactly what you did — send a list as bytes rather than ASCII (as the mxj net.udp.send does). I’m running into a few problems (to put it mildly). One that I can’t figure out is:

C:Program FilesCycling ’74MaxMSP 4.6Cycling ’74javaclassesnetudpsend.java[ 42 ] cannot find symbol
symbol : method charAt(int)
location: class com.cycling74.max.Atom[]
buffer[i] = (byte)a.charAt(i);

It claims there’s no method "charAt(int)", but the code I used is essentially identical to yours:

public void list(Atom[] a) {
int packSize = a.length;
byte[] buffer = new byte[packSize]; // allocate data buffer
for (int i=0; i

buffer[i] = (byte)a.charAt(i);
}
us.send(a);
}

Any ideas? I’m pretty desperate to get this working ASAP, and it’s really frustrating that this small formatting detail could undermine all the other work that’s already happened.

Thanks!

–CJ

February 16, 2008 | 3:43 pm

On 16 Feb 2008, at 03:14, Seejay James wrote:

>
> Hi Volker, I’m trying to use your code to do exactly what you did
> — send a list as bytes rather than ASCII (as the mxj net.udp.send
> does). I’m running into a few problems (to put it mildly). One that
> I can’t figure out is:
>
> C:Program FilesCycling ’74MaxMSP 4.6Cycling ’74javaclasses
> etudpsend.java[ 42 ] cannot find symbol
> symbol : method charAt(int)
> location: class com.cycling74.max.Atom[]
> buffer[i] = (byte)a.charAt(i);
>
> It claims there’s no method "charAt(int)", but the code I used is
> essentially identical to yours:
>
> public void list(Atom[] a) {
> int packSize = a.length;
> byte[] buffer = new byte[packSize]; // allocate data buffer
> for (int i=0; i

> buffer[i] = (byte)a.charAt(i);
> }
> us.send(a);
> }

hi seejay,
not quite. in my code i was using "charAt(int)" on a String not an
Atom[].
please send a private email to me, if you need further help.
volker.

Viewing 9 posts - 1 through 9 (of 9 total)

Forums > MaxMSP