Ejemplo n.º 1
0
int ofxTCPClient::receiveRawMsg(char * receiveBuffer, int numBytes){
	int length=-2;
	//only get data from the buffer if we don't have already some complete message
	if(findDelimiter(tmpBuffReceive.getBinaryBuffer(),tmpBuffReceive.size(),messageDelimiter)==-1){
		memset(tmpBuff,  0, TCP_MAX_MSG_SIZE);
		length = receiveRawBytes(tmpBuff, TCP_MAX_MSG_SIZE);
		if(length>0){ // don't copy the data if there was an error or disconnection
			tmpBuffReceive.append(tmpBuff,length);
		}
	}

	// process any available data
	int posDelimiter = findDelimiter(tmpBuffReceive.getBinaryBuffer(),tmpBuffReceive.size(),messageDelimiter);
	if(posDelimiter>0){
		memcpy(receiveBuffer,tmpBuffReceive.getBinaryBuffer(),posDelimiter);
		if(tmpBuffReceive.size() > posDelimiter + (int)messageDelimiter.size()){
			memcpy(tmpBuff,tmpBuffReceive.getBinaryBuffer()+posDelimiter+messageDelimiter.size(),tmpBuffReceive.size()-(posDelimiter+messageDelimiter.size()));
			tmpBuffReceive.set(tmpBuff,tmpBuffReceive.size()-(posDelimiter+messageDelimiter.size()));
		}else{
			tmpBuffReceive.clear();
		}
	}

	if(posDelimiter>0){
		return posDelimiter;
	}else{
		return 0;
	}
}
//------------------------------------------------------------------------------
void ofxJitterNetworkSender::readResponse()
{
    // TODO read latency data here.
    char buf[MAXDATASIZE]; 
    int numBytes = receiveRawBytes(buf, MAXDATASIZE-1);
    if (numBytes == -1)
    {
        // printf("recv error\n");
        // skip it, there's nothing there
    }
    else
    {
        buf[numBytes] = '\0'; // end it
        
        m_latencyPacket.id                      = ((t_jit_net_packet_latency *)buf)->id; // cast it to get the id
        m_latencyPacket.client_time_original    = ((t_jit_net_packet_latency *)buf)->client_time_original;
        m_latencyPacket.server_time_before_data = ((t_jit_net_packet_latency *)buf)->server_time_before_data;
        m_latencyPacket.server_time_after_data  = ((t_jit_net_packet_latency *)buf)->server_time_after_data;
        
//printf("id: %d\n", (m_latencyPacket.id));
//printf("client time original %f\n",m_latencyPacket.client_time_original);
//printf("before Data %fl\n",m_latencyPacket.server_time_before_data);
//printf("after Data %f\n",m_latencyPacket.server_time_after_data);
//printf("diff=%f\n\n",m_latencyPacket.server_time_after_data - m_latencyPacket.server_time_before_data);
        
        // cout << buf << endl;
        
        // if(lastSent >= m_latencyPacket.client_time_original) {
        //  printf("GTOE => last sent=%f and client_time_original=%f\n",lastSent,m_latencyPacket.client_time_original);	
        // } else {
        //  printf("NNNWWW => last sent=%f and client_time_original=%f\n",lastSent,m_latencyPacket.client_time_original);	
        // }
    }
}
Ejemplo n.º 3
0
//--------------------------
string ofxTCPClient::receive(){
	
	tmpStr = "";
	str    = "";

	//by default get all data in the buffer
	while( receiveRawBytes(tmpBuff, TCP_MAX_MSG_SIZE) > 0 ){
		tmpStr += tmpBuff;
		memset(tmpBuff,  0, TCP_MAX_MSG_SIZE);
	}
		
	int pos = tmpStr.find(STR_END_MSG, 0);
	if(pos >= 0) str = tmpStr.substr(0, pos);	
	
	return str;
}
//------------------------------------------------------------------------------
void ofxMatrixNetworkServer::readResponse()
{
 	//for each connected client lets get the data being sent and lets print it to the screen
	for(unsigned int i = 0; i < (unsigned int)getLastID(); i++){
        
		if( !isClientConnected(i) )continue;

        // TODO read latency data here.
        char buf[MAXDATASIZE]; 
        int numBytes = receiveRawBytes(i, buf, MAXDATASIZE-1);
        if (numBytes == -1)
        {
            // printf("recv error\n");
            // skip it, there's nothing there
        }
        else
        {
            buf[numBytes] = '\0'; // end it
            
            m_latencyPacket.id                      = ((t_jit_net_packet_latency *)buf)->id; // cast it to get the id
            m_latencyPacket.client_time_original    = ((t_jit_net_packet_latency *)buf)->client_time_original;
            m_latencyPacket.server_time_before_data = ((t_jit_net_packet_latency *)buf)->server_time_before_data;
            m_latencyPacket.server_time_after_data  = ((t_jit_net_packet_latency *)buf)->server_time_after_data;
            
    //printf("id: %d\n", (m_latencyPacket.id));
    //printf("client time original %f\n",m_latencyPacket.client_time_original);
    //printf("before Data %fl\n",m_latencyPacket.server_time_before_data);
    //printf("after Data %f\n",m_latencyPacket.server_time_after_data);
    //printf("diff=%f\n\n",m_latencyPacket.server_time_after_data - m_latencyPacket.server_time_before_data);
            
            // cout << buf << endl;
            
            // if(lastSent >= m_latencyPacket.client_time_original) {
            //  printf("GTOE => last sent=%f and client_time_original=%f\n",lastSent,m_latencyPacket.client_time_original);	
            // } else {
            //  printf("NNNWWW => last sent=%f and client_time_original=%f\n",lastSent,m_latencyPacket.client_time_original);	
            // }
        }
    }
}