If I use the pointer instead of the reference like this:
TCPServer.sendRawBytesToAll((char*) *lAudio, sizeof(float));
(I only use a array with one element to make it simpler for myself)
I receive the float value on the client site, but in hex. Can I make some kind of “double” cast (If there is something like this) with the receiveRawBytes object?
If I send my data with the reference:
TCPServer.sendRawBytesToAll((char*) lAudio, sizeof(float));
do I only get the address of the pointer on the client site. (Is there some dereference I do not understand?)
Just to be clear, here’s my code:
ofApp.h - Server
#pragma once
#include "ofMain.h"
#include "ofxNetwork.h"
class ofApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
void keyPressed(int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
enum TCPState {
IDLE,
LOADING_SOUND,
SENDING_SOUND,
SEND_ONE
};
TCPState state;
ofxTCPServer TCPServer;
ofSoundStream soundStream;
void audioIn(float *input, int bufferSize, int nChannels);
float* lAudio[1];
};
ofApp.cpp - Server
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
TCPServer.setup(50002);
soundStream.setup(this, 0, 2, 44100, 256, 4);
}
//--------------------------------------------------------------
void ofApp::update(){
}
//--------------------------------------------------------------
void ofApp::audioIn(float* input, int bufferSize, int nChannels){
for (int i = 0; i < bufferSize && state == LOADING_SOUND; i++) {
lAudio[i] = &input[i * nChannels];
*lAudio[i] = fabsf(*lAudio[i]);
*lAudio[i] = *lAudio[i] * 100.0f;
state = SEND_ONE;
}
//temp function
if (state == SEND_ONE) {
cout << "Float :" << *lAudio[0] << endl << endl;
cout << "Pointer :" << *lAudio << endl;
cout << "Reference :" << lAudio << endl << endl;
//Just for check on the client site
cout << "float in hex :" << ofToHex(*lAudio[0]) << endl;
TCPServer.sendRawBytesToAll((char*) *lAudio, sizeof(float));
}
state = IDLE;
}
//--------------------------------------------------------------
void ofApp::draw(){
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
if (key == 's') {
state = LOADING_SOUND;
}
}
ofApp.h - Client
#pragma once
#include "ofMain.h"
#include "ofxNetwork.h"
class ofApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
void keyPressed(int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
ofxTCPClient TCPClient;
enum tcpState {
LISTEN,
RECEIVE
};
tcpState state;
float* lAudio[1];
};
ofApp.cpp - Client
#include "ofApp.h"
#include <string>
//--------------------------------------------------------------
void ofApp::setup(){
TCPClient.setup("127.0.0.1", 50002);
if (TCPClient.isConnected()) {
cout << "ONLINE" << endl;
}
}
//--------------------------------------------------------------
void ofApp::update(){
if ((int)TCPClient.receiveRawBytes((char *)lAudio,sizeof(float)) > 1) {
cout << "Pointer Reference : " << lAudio << endl;
cout << "Pointer : " << *lAudio << endl; //The float in hex
}
}
My server code is a little messy but at this point I just really want to understand how to get it working.