help oscP5 via UDP

edited December 2013 in Library Questions

hi friend.I want to create Server Client application with OSC over UDP.can you show me simple examples.oscP5 library only has TCP example.THANKS

Answers

  • edited December 2013

    You can take the TCP example and just change the initialization of the client and the server like so:

    oscP5tcpServer = new OscP5(this, 11000, OscP5.UDP);
    oscP5tcpClient = new OscP5(this, "127.0.0.1", 22000, OscP5.UDP);
    

    It looks like you are not allowed to use the same port for sending and receiving though. Maybe someone with a better understanding of network protocols than mine will be able to explain why this works in TCP and not in UDP.

  • my friend thanks for answer.but i tried it but doesnt works.there is warning WARNING @ OscNetManager.send please specify a remote address. send(OscPacket theOscPacket) is only supported when there is a host specified in OscProperties.

  • Answer ✓

    Hi, by default all OSC communication with oscP5 is odne over UDP. though, you can specify the transport protocol (see oscP5tcp example). The following example will send osc messages to itself using the UDP protocol

    import oscP5.*;
    import netP5.*;
    // this example uses oscP5 0.9.9
    OscP5 osc;
    NetAddress remote;
    void setup() {
    
      // start oscP5 and listen for UDP messages on port 12000
      osc = new OscP5(this,12000);  
    
      // define a remote Address which we want to receive OSC messages
      // a NetAddress requires an IP address as first argument 
      // and a port number as second argument
      remote = new NetAddress( "127.0.0.1" , 12000 );
    }
    
    void draw() {
    }
    
    void mousePressed() {
      OscMessage m = new OscMessage("/test");
      // add 3 values to the OscMessage /test
      m.add(1).add(2).add(3);
      // now send the OscMessage to the remote location defined earlier
      osc.send(m,remote);
    }
    
    void oscEvent(OscMessage m) {
      println(m);
    }
    
  • edited December 2013

    thank you for answering.in the server side do i have to use this part?,server side receives datas but it doesnt send datas?

    WARNING @ OscNetManager.send please specify a remote address. send(OscPacket theOscPacket) is only supported when there is a host specified in OscProperties.

    >  import oscP5.*;
        import netP5.*;
        // this example uses oscP5 0.9.9
        OscP5 osc;
    
        void setup() {
          // start oscP5 and listen for UDP messages on port 12000
          osc = new OscP5(this,12000);  
    
        }
    
        void draw() {
        }
    
        void mousePressed() {
          OscMessage m = new OscMessage("/test");
          // add 3 values to the OscMessage /test
          m.add(1).add(2).add(3);
          // now send the OscMessage to the remote location defined earlier
          osc.send(m);
        }
    
        void oscEvent(OscMessage m) {
          println(m);
        }
    
  • edited December 2013 Answer ✓

    like the warning message says, there is no remote address specified - since you took it out. you can add

    osc.properties().setRemoteAddress("127.0.0.1" , 12000 );

    after

    osc = new OscP5(this,12000);

    to your previous post to set the remote address inside OscProperties, this will then default to the default remote address.

  • edited December 2013

    My friend I want my server to send message to all connected clients.with tcp I have did it.server receives message from one client and sends to anathor client and back.it acts like bridge between two clients .on the server side I didnt type my clients ip adresses.when clients connects server gets ip adresses and answers to this ip adresses.but now you says i have to type all my clients ip adresses on the server.I have not oscP5 0.9.9.

  • edited December 2013

    the short answer is, yes you do. you can use an NetAddressList to store all remote addresses. when you send an OSC message you can use this list to distribute this message to all remote addresses stored inside this list. There is the oscP5broadcaster example that mimics the behavior of an 'UDP-server'. the oscP5boradcastClient shows you how to connect to the oscP5broadcaster

    UDP is a connection-less network protocol as opposed to TCP which requires a client to connect to a server to establish a connection - a handshake. UDP on the other hand just sends out UDP packets to a remote address without even knowing if this remote address exists - UDP is unreliable, there is no guarantee of delivery, but makes it more suitable than TCP for real time applications

    Time-sensitive applications often use UDP because dropping packets is preferable to waiting for delayed packets, which may not be an option in a real-time system. wikipedia, User Datagram Protocol

Sign In or Register to comment.