Connecting to a UDP data stream with Mathematica -


i have app on iphone called iseismometer reads iphone's accelerometers , acts server streams data via udp (i can set ip address , port number). question how read data stream mathematica? apparently, dreeves has been looking 12 years ago, imagine must have happened in meantime.

update
got 2 great answers far; 1 wreach , 1 mark mcclure. both using jlink @ data. seems fine approach. however, reminded of work did on wii balance board. using few free programs (glovepie , ppjoy) got bluetooth peripheral appear joystick windows, , therefore mathematica (via controllerstate). of course, bluetooth , udp quite different, along same lines made work too?

jlink way go. prefer keep java code , mathematica code separate compiling java programwhich call mathematica. set notebook , companion java program can grab here: http://facstaff.unca.edu/mcmcclur/udpfiles.tar.gz

here essential mathematica code:

needs["jlink`"]; installjava[]; addtoclasspath[notebookdirectory[]]; udpreader = javanew["myclient"]; = 0; while[true && i++ < 100,   print[udpreader@udpreadone[10552]]] 

the updreader class defined following java code.

// simple udp client read iseismometer: // http://www.iseismometer.com/ // can run command line via "java myclient" // check iseismometer setup correct or can // call the udpreadone method program.  import java.io.*; import java.net.*; import java.util.*;  public class myclient {     public static void main() throws ioexception {         datagramsocket socket = new datagramsocket(10552);         byte[] buffer = new byte[500];         datagrampacket packet = new datagrampacket(buffer, buffer.length);         while(true) {             socket.receive(packet);             string received = new string(packet.getdata(), 0, packet.getlength());             system.out.println(received);         }     }      public static string udpreadone(int port) throws ioexception {         datagramsocket socket = new datagramsocket(port);         byte[] buffer = new byte[100];         datagrampacket packet = new datagrampacket(buffer, buffer.length);         socket.receive(packet);         string received = new string(packet.getdata(), 0, packet.getlength());         socket.close();         return received;     } } 

note can use main method of myclient class check setup working without mathematica, taking 1 potential issue out of loop.


Comments