There is a client, there is a server, and there is an "intermediary" between them . The client connects to the intermediary, the intermediary stupidly takes and transfers the data to the server. The fact is that when the text is transferred (tested on the http \ ftp protocols), the "proxy" program normally transfers data. But when binary ... not sure. He also sends them, but the client program can not recognize the data so to speak. An array of type char is used for transmission. Is it possible that when receiving data, some elements of the array overflow and the data is distorted? MB should use a different data type for the buffer?
I decided to test http, raised the server. I tried to download the file zip 2.9mb. I noticed that when I set the size of the buffer in the "intermediary" to receive 3000 bytes, it downloads 360kb and stops when 64b downloads 2.6mb and stops; when 8b, the browser does not quite understand what is coming to it. The file opens with a solid text, but this sometimes happens on ordinary Internet. Also on the size of the incoming buffer in the "intermediary" noticeable difference in speed. How to be, I do not know. Yes, in SDLNet, as noted, there are functions for writing data to the internetwork format in order to get around big endian \ little endian. But I shook myself on a local host myself. No matter how this should probably be at home, the future should probably be taken care of. I attach project files. Maybe someone will want to understand the code. To compile, you need to download and install SDL and SDL_net .
Those who are too lazy to download, here are the listings. main.cpp and tcputil.h
Issue resolved
Thanks to alexlz for hint. As a result, the function of receiving transmission look like.
#ifndef tcputil_h #define tcputil_h 1 #include "sdl/SDL.h" #include "sdl/SDL_net.h" const unsigned size=1024; char* getMsg(TCPsocket sock,int &n) { static char buf[size]; n=SDLNet_TCP_Recv(sock,buf,size); /* get the string buffer over the socket */ if(n<0) { if(SDLNet_GetError() && strlen(SDLNet_GetError())) /* sometimes blank! */ printf("SDLNet_TCP_Recv: %s\n", SDLNet_GetError()); //free(*buf); return NULL; } /* return the new buffer */ return buf; } /* send a string buffer over a TCP socket with error checking */ /* returns 0 on any errors, length sent on success */ int putMsg(TCPsocket sock, char *str,int n) { /* send the buffer, with the NULL as well */ if(SDLNet_TCP_Send(sock,str,n)<n) { if(SDLNet_GetError() && strlen(SDLNet_GetError())) /* sometimes blank! */ printf("SDLNet_TCP_Send: %s\n", SDLNet_GetError()); return(0); } /* return the length sent */ return n; } #endif
Well, yes, it was worth removing any printf () as the transfer rate increased to "you do not have time to blink."