Created
August 8, 2012 16:57
-
-
Save oferreiro/3296647 to your computer and use it in GitHub Desktop.
sender function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define UDP_HEAD_SIZE 65 | |
#define UDP_MAX_DATA_SIZE 1034 | |
#define UDP_MSG_SIZE UDP_HEAD_SIZE+UDP_MAX_DATA_SIZE+1 | |
void udpSender::sendImage(){ | |
int dataPosID = 0; | |
char *index = compressedBuffer.getBinaryBuffer(); | |
char udpPack[UDP_MSG_SIZE]; | |
char *udpHead = &udpPack[0]; | |
char *udpData = &udpPack[UDP_HEAD_SIZE]; | |
memset(udpPack,0, UDP_MSG_SIZE); | |
if (frameId >= RESET_FRAME_ID) frameId = 0; | |
headManager.setFrameIndex(frameId); | |
headManager.setTotalBufferSize(compressedBuffer.size()); | |
while (dataPosID < compressedBuffer.size()) { | |
int dataLeft = compressedBuffer.size() - dataPosID; | |
int length; | |
if (dataLeft > UDP_MAX_DATA_SIZE) length = UDP_MAX_DATA_SIZE; | |
else length = dataLeft; | |
headManager.setBlockIndex(dataPosID); | |
headManager.setBlockSize(length); | |
headManager.getHead(udpHead); | |
lock(); | |
memcpy(udpData,index,length); | |
unlock(); | |
// put nul char on last data char | |
udpData[length] = '\0'; | |
//Only send head | |
//int sent = udpConnection.Send(udpHead,UDP_HEAD_SIZE); | |
int sent = udpConnection.SendAll(udpPack, UDP_MSG_SIZE); | |
if (sent==-1 || sent ==0){ | |
sendErrorCount++; | |
}else{ | |
sendSucessCount++; | |
sentPacksCount+=sent; | |
} | |
index += length; //increase pointer so that it points to next block | |
dataPosID += length; //increase sent count | |
} | |
frameId++; | |
ofSleepMillis(NET_ACT_SLEEP); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment