Jump to content
  • Advertisement
Sign in to follow this  
kahwai

How to send image data over the network?

This topic is 4595 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,i would like to know that how to send the image data over the network.I captured the screen into a device context and i would like to send it to the server side so that server can save it as image. I'm using c++ with mfc and my target platform is windows based pc. Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
Well, it's a bit hard to answer your question without knowing your background. However, you can consult MSDN for tutorials on Winsock, the Win32 sockets API. Sockets are used for communicating with other computers. Basically you need to open a socket to the other computer, which is ready to accept your incoming connections, and then you can simply send the data to that remote connection. On the other side you'll need to receive the data and there you have it.

Share this post


Link to post
Share on other sites
Since you are using MFC you can create a CSocket for the network connection, the associate a CSocketFile with the CSocket and then attach a CArchive. Once you have the CArchive you can use a CBitmap to get the screen image from the device context and then serialize the CBitmap on the CArchive.

Share this post


Link to post
Share on other sites
I would recommend compressing the image to something like JPEG before transmitting it -- the size difference between BMP and JPG can be 10x, and with networking, size matters. Only if you need a perfect replica of the screen should you not use something like JPEG (although PNG likely will still do better than BMP).

If you're on Windows, you can also use the built-in internet service interfaces and create a POST request that sends the image to a web service of your choice.

Share this post


Link to post
Share on other sites
Thanks for the replies above. I tried to use the CSocketFile and CArchive method but my problem is i can't retried the CBitmap.I have something like below:

if(ar.IsStoring())
ar<<bmp;
else
ar>>bmp;



ar is a variable of CArchive and I got compile error for ar>>bmp.

error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'CBitmap' (or there is no acceptable conversion)



I would like to try to convert it to png file format before transmitting as well but how to create a CImage data from the device context of the image and make it serializeable for CArchive?

Share this post


Link to post
Share on other sites
It's really unoptimized but what's stopping you from writing whatever image to disk and repeatedly doing an fstream.read(byte) followed by a socket.send(byte)? Once you can get the Bitmap object into a byte array, sending it's a piece of cake in or out of MFC. CArchive has really been more trouble than it was worth IMO, so I don't know why MSDN recommends it.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmfc98/html/_mfc_cbitmap.3a3a.getbitmapbits.asp

That's a link to MSDN's entry on CBitmap. You have to give it a number of bytes to copy (which the last line or so says how to get) and a pointer to a byte array. I'd second trying to find a way to compress it to something other than a raw bitmap, and that's elementary to do in C#, but you're on your own in C++ though you do have over 20 years of libraries out there.

Share this post


Link to post
Share on other sites
Quote:
Original post by RKillian
It's really unoptimized but what's stopping you from writing whatever image to disk and repeatedly doing an fstream.read(byte) followed by a socket.send(byte)? Once you can get the Bitmap object into a byte array, sending it's a piece of cake in or out of MFC. CArchive has really been more trouble than it was worth IMO, so I don't know why MSDN recommends it.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmfc98/html/_mfc_cbitmap.3a3a.getbitmapbits.asp

That's a link to MSDN's entry on CBitmap. You have to give it a number of bytes to copy (which the last line or so says how to get) and a pointer to a byte array. I'd second trying to find a way to compress it to something other than a raw bitmap, and that's elementary to do in C#, but you're on your own in C++ though you do have over 20 years of libraries out there.



I don't want to save it into the disk first because I scare the player might hack the image before it sends to server.

Share this post


Link to post
Share on other sites
Use GetObject to get the necessary information about the bitmap. Send this information using the socket stream to the server. The server can then reconstruct the bitmap and do whatever it needs.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!