Solved

send pictures through the winsock control

Posted on 1998-10-28
11
623 Views
Last Modified: 2013-11-13
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.
0
Comment
Question by:otroligafredde
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 12

Expert Comment

by:mark2150
Comment Utility
Would think you'd have to send it as a *file*. Handle it like any other file attachment.

M
0
 
LVL 1

Expert Comment

by:Chamberlain
Comment Utility
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)




0
 
LVL 2

Expert Comment

by:peterwest
Comment Utility
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....

Pete

0
 
LVL 2

Expert Comment

by:peterwest
Comment Utility
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!!

Pete

0
 
LVL 2

Expert Comment

by:peterwest
Comment Utility
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.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Expert Comment

by:Chamberlain
Comment Utility
I'm sorry peter but you make it sound like it's hard.  It's nothing more than a

SavePicture
Open MyPic as Binary
Get Data

on one side
and on the other side...

Open MyPic as Binary
Put Data
LoadPicture

Then delete the files on each side.

Am I missing something?
0
 
LVL 2

Expert Comment

by:peterwest
Comment Utility
Chamberlain:

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.

pete
0
 
LVL 3

Author Comment

by:otroligafredde
Comment Utility
Peter, please send me your solution
to the problem.

0
 
LVL 3

Author Comment

by:otroligafredde
Comment Utility
Peter:
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.

0
 
LVL 2

Accepted Solution

by:
peterwest earned 100 total points
Comment Utility
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 'peterjwest@yahoo.com'  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.

Cheers

Pete

0
 
LVL 3

Author Comment

by:otroligafredde
Comment Utility
Peter:

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

0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now