Quantcast
Channel: openFrameworks - Latest posts
Viewing all articles
Browse latest Browse all 40524

ofxUDPManager - bi directionnal

$
0
0

Thank you again for your help. Indeed you example works fine. For my project, i need to broadcast message on a local network and i receive from multiple devices on this same local network (this devices broadcast the UDP message too).

Anyway, when I try the code bellow, when I press a key for the first time the message is well sent and received, but when i press again the key, the message is not sent. The weird thing is that it seems send and received looking at the output generated by ofLogError(), but when i sniff the network i see the first key pressed sent, but not the others.

If i manage this with two ofxUDPManager object (one for send and the other for receive) it works, but regarding your advise it must work too with only one ofxUDPManager object.

#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){
    
    server.Create();
    server.SetNonBlocking(true);
    server.Bind(11009);
    server.Connect("192.168.1.255", 11009);
    server.SetEnableBroadcast(true);
    
    
    
}

//--------------------------------------------------------------
void ofApp::update(){
    char udpMessage[1000];
    string messageReceived;
    auto ret = server.Receive(udpMessage, 1000);
    if(ret>=0){
        messageReceived.assign(udpMessage);
        if(messageReceived.length()>0){
            ofLogError() << messageReceived;
        }
    }
}

//--------------------------------------------------------------
void ofApp::draw(){
    
}

//--------------------------------------------------------------
void ofApp::keyPressed(int key){
    
    
}

//--------------------------------------------------------------
void ofApp::keyReleased(int key){
    std::string messageSent="message";
    server.Send(messageSent.c_str(), messageSent.size());
    
}

Viewing all articles
Browse latest Browse all 40524

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>