After sending an image through the network and reconstructing it with the create command everything gets shifted quite a few pixels to the right. So the obvious question is, what is causing this behaviour?
Server side:
http://imgur.com/aVMI2Sr.pngClient side:
http://imgur.com/CVjhuJy.pngServer side send code:
data_block.data_value_1 = size_;
data_block.data_value_2 = image.getSize().x;
data_block.data_value_3 = image.getSize().y;
send(sockets_[num_clients_], (char*)&data_block, DEFAULT_BUFLEN, 0);
int temp_count = 0, wait_for_send;
char temp_arr[1000];
unsigned char * img_arr = (unsigned char *)image.getPixelsPtr();
memcpy(temp_arr, img_arr+temp_count, 1000);
while(temp_count < size_){
// Send image in smaller portions
wait_for_send = send(sockets_[num_clients_], temp_arr, 1000, 0);
if(wait_for_send > 0){
memcpy(temp_arr, img_arr+temp_count, wait_for_send);
temp_count += wait_for_send;
}
}
Client side receive code(The first package is received in another function and passes the data to this function):
size_p = new unsigned char[(unsigned int)p->data_value_1];
int temp_count = 0, wait_for_recive, image_size = p->data_value_1;
char temp_arr[1000];
while(temp_count < image_size){
// Receive the image in smaller portions
wait_for_recive = recv(connect_socket_, temp_arr, 1000, 0);
if(wait_for_recive > 0){
memcpy(size_p+temp_count, temp_arr, wait_for_recive);
temp_count += wait_for_recive;
}
}
// Create the new image
gImages.create("I_Image", p->data_value_2, p->data_value_3, size_p);
Edit : The issue went away entirely when I rewrote the send code to a do while loop instead and removed the if statement, which means the if loop was screwed up.
do{
memcpy(temp_arr, img_arr+temp_count, 1000);
// Send image in smaller portions
wait_for_send = send(sockets_[num_clients_], temp_arr, 1000, 0);
temp_count += wait_for_send;
}
while(temp_count < size_);