tcp - Sending Bitmap data over winsock? Winapi -
i tring send screenshot of desktop on winsock.
as such, there 4 tasks:
save bitmap buffer write data across wire using socket read data wire using socket load bitmap buffer
i have saved bitmap char array using getdibits. writing data server, have done have questions. writing data on server client, need use 1 recv() call (i using tcp), or need split multiple parts? ive read tcp stream concept , wouldnt have worry packets because abstracted me?
how go loading information getdibits bitmap , displaying on main window?
i guessing have use setdibits, device contexts use?
the server screenshot capturer here:
hdc handle_screendc = getdc(null); hdc handle_memorydc = createcompatibledc(handle_screendc); bitmap bitmap; int x = getdevicecaps(handle_screendc, horzres); int y = getdevicecaps(handle_screendc, vertres); hbitmap handle_bitmap = createcompatiblebitmap(handle_screendc, x, y); selectobject(handle_memorydc, handle_bitmap); bitblt(handle_memorydc, 0, 0, x, y, handle_screendc, 0, 0, srccopy); getobject(handle_bitmap, sizeof(bitmap), &bitmap); bitmapfileheader bmfheader; bitmapinfoheader bi; bi.bisize = sizeof(bitmapinfoheader); bi.biwidth = bitmap.bmwidth; bi.biheight = bitmap.bmheight; bi.biplanes = 1; bi.bibitcount = 16; bi.bicompression = bi_rgb; bi.bisizeimage = 0; bi.bixpelspermeter = 0; bi.biypelspermeter = 0; bi.biclrused = 0; bi.biclrimportant = 0; //std::cout<< bitmap.bmwidth; dword dwbmpsize =((bitmap.bmwidth * bi.bibitcount + 5) / 32) * 4 * bitmap.bmheight; //int = bitmap.bmwidth; //dword dwbmpsize = 99; handle hdib = globalalloc(ghnd, dwbmpsize); char* bufptr = (char *)globallock(hdib); getdibits(handle_screendc, handle_bitmap, 0, (uint)bitmap.bmheight, bufptr, (bitmapinfo *)&bi, dib_rgb_colors); send(clientsock, bufptr , globalsize((char *)globallock(hdib)), 0); /*do need packetize/split up? or 1 send() matching recv on client?*/ /*i assuming must send bi structure on winsock correct?*/
and receiveing client code:
case wm_paint:{ //im gdi beginner dont have clue im doing here far blitting recved bits, stuff tried myself before asking paintstruct paintstruct; hdc handle_windowdc = beginpaint(hwnd, &paintstruct); handle_memorydc = createcompatibledc(handle_windowdc); handle_bitmap = createcompatiblebitmap(handle_windowdc, 640, 360); std::cout << setdibits(handle_memorydc, handle_bitmap, 0, bi.biheight, buffer, (bitmapinfo *)&bi, dib_rgb_colors); selectobject(handle_memorydc, handle_bitmap); stretchblt(handle_windowdc, 50, 50, 640, 360, handle_memorydc, 0, 0, x, y, srccopy); endpaint(hwnd, &paintstruct); }
sockets have limited buffer sizes @ both ends, typically around 4000 bytes. if dump large block of data (like full screendump) in 1 call non-blocking send, errors, , need manage own buffers, calling multiple sends. however, if using non-blocking socket, should ok, send() block until data sent.
on receiving side, similar case - blocking receive can keep waiting until has full data size asked for, non-blocking receive return whatever data available @ time, result in data filtering through bit bit, , need reassemble data multiple recv() calls.
i have heard of issues sending large blocks of data in 1 hit, if sending 5 megabytes of data in 1 hit, aware there might other issues coming play well.
Comments
Post a Comment