send pictures through the winsock control

I have a server application with a picturebox, this
application is connected to a client application
that also have a picturebox.

I wan't to send .gif pictures between the two application.
I have tried to send them using this line:
winsock1.senddata pic1.picture

but I don't know how to write the DataArrival for it.
If anyone knows how to do it, please answer me.
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

peterwestConnect With a Mentor Commented:
Hi again - apologies for the day,

Right then - i've now written a control which does the following:

1) It works in exactly the same way as a standard winsock control; in fact, it's based on it but extends it's functionality.  It has the following:

    a) An extra property called PictureWindow.  This is just the name of a picture box where any received images will be displayed.
    b) An extra method called SendPicture.  Simple go like this:
             ImageSock1.SendPicture Picture1
       to send the image in picturebox Picture 1.

All of this is totally transparent.  There are two things I can do - bearing in mind the aim of this site is to share knowledge.   I will either

A) Post the entire source code the the control (not my preferred way)
B) If anyone want's to e-mail me their e-mail address at ''  I will e-mail you both the control and a VB6 program that shows you how to use the control.  As well as sending the control i'll also send the source files as well.

Let me know what you'd like me to do.



Would think you'd have to send it as a *file*. Handle it like any other file attachment.

Unfortunatley, you have no way of doing it strictly in VB then to save it to a file, send the file and on the other side, write the file and open it with load picture.

I've done it in memory by using the LEAD tools.  It has a LoadPictureFromMemory method (or something like that) that allows you to load it from a byte array.  If you use a control that can do that (PictureBox can't) can create a byte array that is large enough to hold the picture and copy the picture into the byte array with memcopy

Declare Sub MemCopy Lib "kernel32" Alias "RtlMoveMemory" (rOvDestination As
Any, rIvSource As Any, ByVal vIlSize As Long)

send the byte array and on the other side, store it in another byte array then use the controls method to load from memory.  I wish I had a better answer for you.

On the flipside, writing temporarily to the disk, opening the file as binary, sending the contents and on the other side writing the contents as is to a new file and then using LoadPicture then delete the files will work and really isn't slow (as compared to the networking)

The new generation of project management tools

With’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Hmmm, here's an idea - you could cheat!!!

If the following suggestion is acceptable i'll have a look at writing code to achieve it.

1) Use SavePicture command to write the contents of the picturebox to a file.
2) Send the file through the winsock control.
3) At the receiving end capture the picture data and write this to a temporary file.
4) Use the LoadPicture command to load it into the destination picturebox.

There probably is a more elegant way to do it by using API calls - but this is probably the quickest and easiest way to achieve it.  I've not tested this but it should, in theory, work....


Apologies for posting a reply that someone had already given - I got loads of errors whilst trying to submit my comment and when it finally went through someone had obviouslly beaten me to it!!


Ok then,

I've looked into this and i've now got the code to create the temporary file, trasmit it, receive it at the other end, write it to file and then load it into the box!!! Phew!!

Let me know if you want me to post it.
I'm sorry peter but you make it sound like it's hard.  It's nothing more than a

Open MyPic as Binary
Get Data

on one side
and on the other side...

Open MyPic as Binary
Put Data

Then delete the files on each side.

Am I missing something?

No, you're not missing anything - apart from actually transferring that data through the winsock control - it's NOT hard to do and it only took me about 5 minutes to knock up the code that achieves the aim.

otroligafreddeAuthor Commented:
Peter, please send me your solution
to the problem.

otroligafreddeAuthor Commented:
I have tried to create the temporary file, trasmit it, receive it at the other end, write it to file and then load it into the box. but I just can't get it to work.
I would be grateful if you would post your code.

otroligafreddeAuthor Commented:

This sounds exellent!
I'll e-mail my address.

All Courses

From novice to tech pro — start learning today.