Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

limit for OSC message #6

Open
knupel opened this issue Jun 13, 2017 · 4 comments
Open

limit for OSC message #6

knupel opened this issue Jun 13, 2017 · 4 comments

Comments

@knupel
Copy link

knupel commented Jun 13, 2017

Hello,
I try to send message, but I found a different limit for each type of argument.
That's depend of my computer or it's a limit of the OSC ? It(s possible to increase this limit ?
Or don't stop Processing and just limit the the size of the package must be sent and print a warning to inform the user ?

and thx for your work.

Processing 3.3.4 OS Sierra Osc 2.0.4

String limit 1524 java.lang.ArrayIndexOutOfBoundsException

Array float limit 1842 Could not send datagram java.net.SocketException: Message too long

Array int limit 306 java.lang.ArrayIndexOutOfBoundsException

Boolean limit 9207 Could not send datagram java.net.SocketException: Message too long

Here the little sketch I code to find the limit.

import oscP5.*;
import netP5.*;

OscP5 oscP5;
NetAddress myRemoteLocation;
// OscP5 osc_receive_controller ;

void setup() {
  size(400,400);
  /* start oscP5, listening for incoming messages at port 12000 */
  int port = 10_000 ;
  oscP5 = new OscP5(this,port);
  myRemoteLocation = new NetAddress("127.0.0.1",port);
}


void draw() {
  background(0);
  send() ;
}



int count_send = 0 ;
String string_limit = ("");
void send() {
  count_send++ ;
  
  OscMessage myMessage = new OscMessage("test");
  /*
  string_limit = string_limit + "a" ;
  myMessage.add(string_limit); // add an int to the osc message
  println("String limit", string_limit.length()) ;
  */


  boolean [] bool_limit = new boolean[count_send];
  for(int i = 0 ; i < bool_limit.length ; i++) {
    bool_limit[i] = true ;
    myMessage.add(bool_limit[i]); // add an int to the osc message
  }
  
  println("Boolean limit", bool_limit.length);
  
  
  /*
  int [] array_int = new int[count_send] ;
  for(int i = 0 ; i < count_send ; i++) {
    // array_int[i] = floor(random(MAX_INT)) ;
    array_int[i] = i ;
  }
  myMessage.add(array_int); // add an int to the osc message
  println("Array int limit", array_int.length) ;
  */
  

  /* 
  float [] array_float = new float[count_send] ;
  for(int i = 0 ; i < count_send ; i++) {
    // array_int[i] = floor(random(MAX_INT)) ;
    array_float[i] = i ;
  }
  myMessage.add(array_float); // add an int to the osc message
  println("Array float limit", array_float.length) ;
  */
 
  
  /*
  myMessage.add(123); // add an int to the osc message
  myMessage.add(12.34); // add a float to the osc message
  myMessage.add("some text"); // add a string to the osc message
  myMessage.add(new byte[] {0x00, 0x01, 0x10, 0x20}); // add a byte blob to the osc message
  myMessage.add(new int[] {1,2,3,4}); // add an int array to the osc message
  */

  /* send the message */
  oscP5.send(myMessage, myRemoteLocation); 
}
@knupel
Copy link
Author

knupel commented Jun 24, 2017

Just in case I update the sketch test for the big message:
sometime there is an IndexOutbound... blablah, sometime your error message message too longand the difference of length between them is huge.

/**
 * oscP5message by andreas schlegel
 * example shows how to create osc messages.
 * oscP5 website at http://www.sojamo.de/oscP5
 */
 
import oscP5.*;
import netP5.*;

OscP5 oscP5;
NetAddress myRemoteLocation;
// OscP5 osc_receive_controller ;

void setup() {
  size(400,400);
  /* start oscP5, listening for incoming messages at port 12000 */
  int port = 10_000 ;
  oscP5 = new OscP5(this,port);
  myRemoteLocation = new NetAddress("127.0.0.1",port);
}


void draw() {
  background(0);
  send() ;
}



int count_send = 0 ;

float bool_unit = 1. ;
float misc_unit = 5. ;
float string_unit =  6.1 ;

void send() {
  count_send++ ;
  
  OscMessage myMessage = new OscMessage("test");
  /*
  string_limit = string_limit + "a" ;
  myMessage.add(string_limit); // add an int to the osc message
  println("String limit", string_limit.length()) ;
  */

     /**
   Array int limit 306
   String limit 1524
   java.lang.ArrayIndexOutOfBoundsException
   */
   /**
  Parfois va jusqu'à cette limite quand la ligne oscP5.send() a été mis en commentaire puis réactivée.... bizarre
   array limit 1842 
   String limit 9204 
   Could not send datagram java.net.SocketException: Message too long
   */



 // byte_limit(myMessage) ; // 1842 or 305 

  boolean_limit(myMessage) ; // 9207 no IndexOout for this time

   // int_limit(myMessage); // 1842 or 305 

  // float_limit(myMessage); // 1842 or 305

  // char_limit(myMessage); // 1842 or 305

  // string_limit(myMessage); // 9204 or 1524

   // string_limit_unit(myMessage); // 1842 or 305

   // object_limit(myMessage); // 1842 or 305


  /* send the message */
  oscP5.send(myMessage, myRemoteLocation); 
}


String string_limit =("");
void string_limit(OscMessage myMessage) {
  string_limit += "a" ;   
  myMessage.add(string_limit); // add an int to the osc message
  println("String limit", string_limit.length()) ;
}



void string_limit_unit(OscMessage myMessage) {
  String [] array_string = new String [count_send];
  for(int i = 0 ; i < count_send ; i++) {
     array_string[i] = "a" ;
    myMessage.add(array_string[i]); // add an int to the osc message
  }
  println("String limit", array_string.length) ;
}



void object_limit(OscMessage myMessage) {
  Object [] array_obj = new Object[count_send] ;
  for(int i = 0 ; i < count_send ; i++) {
    array_obj[i] = i ;
    myMessage.add(array_obj[i]); // add an int to the osc message
  }
  println("Array object limit", array_obj.length) ;
}

void char_limit(OscMessage myMessage) {
  char [] array_char = new char[count_send] ;
  for(int i = 0 ; i < count_send ; i++) {
    array_char[i] = 'e' ;
    myMessage.add(array_char[i]); // add an int to the osc message
  }
  println("Array char limit", array_char.length) ;
}



void float_limit(OscMessage myMessage) {
  float [] array_float = new float[count_send] ;
  for(int i = 0 ; i < count_send ; i++) {
    array_float[i] = i ;
    myMessage.add(array_float[i]); // add an int to the osc message
  }
  println("Array float limit", array_float.length) ;
}


void int_limit(OscMessage myMessage) {
  int [] array_int = new int[count_send] ;
  for(int i = 0 ; i < count_send ; i++) {
    array_int[i] = i ;
    myMessage.add(array_int[i]); // add an int to the osc message
  }
  println("Array int limit", array_int.length) ;
}


void boolean_limit(OscMessage myMessage) {
  boolean [] bool_limit = new boolean[count_send];
  for(int i = 0 ; i < bool_limit.length ; i++) {
    bool_limit[i] = true ;
    myMessage.add(bool_limit[i]); // add an int to the osc message
  }
  println("Boolean limit", bool_limit.length);
}



void byte_limit(OscMessage myMessage) {
  byte [] byte_limit = new byte[count_send];
  for(int i = 0 ; i < byte_limit.length ; i++) {
    byte_limit[i] = '1' ;
    myMessage.add(byte_limit[i]); // add an int to the osc message
  }
  println("Byte limit", byte_limit.length);
}

@micuat
Copy link

micuat commented Jun 25, 2017

I was looking for the same issue (not for sender but for receiver) and I figured out that you need OscProperties::setDatagramSize like

void setup() {
  size(400, 400);
  /* start oscP5, listening for incoming messages at port 12000 */
  int port = 10_000 ;
  OscProperties op = new OscProperties();
  op.setListeningPort(10000);
  op.setDatagramSize(5000);
  oscP5 = new OscP5(this, op);
  myRemoteLocation = new NetAddress("127.0.0.1", port);
}

to increase the data size, for example, to 5,000. Note that data includes osc address and other metadata (?) so you can send a bit less than 5,000 characters in this case.

@knupel
Copy link
Author

knupel commented Jun 25, 2017

Thx @micuat for the trick, now I can push to the limit of the datagram, 1842 for the classic array type like int, float, String...
the limit is
op.setDatagramSize(9220); // 9220 is the max to push to the datagram limit

@cristianvogel
Copy link

For those that might run into Index Out Of Bounds errors when trying to parse incoming messages. The reason could be that the type is one that needs a larger datagram size. I ran into it when trying to parse messages from the Moss OSC controller script for Bitwig, probably caused by the {color} type being send by messages such as /vkb_midi/note/{0-127}/color

The fix above posted by @micuat solves that error in oscP5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants