Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 637
  • Last Modified:

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.
0
otroligafredde
Asked:
otroligafredde
  • 5
  • 3
  • 2
  • +1
1 Solution
 
mark2150Commented:
Would think you'd have to send it as a *file*. Handle it like any other file attachment.

M
0
 
ChamberlainCommented:
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
 
peterwestCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
peterwestCommented:
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
 
peterwestCommented:
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
 
ChamberlainCommented:
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
 
peterwestCommented:
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
 
otroligafreddeAuthor Commented:
Peter, please send me your solution
to the problem.

0
 
otroligafreddeAuthor Commented:
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
 
peterwestCommented:
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
 
otroligafreddeAuthor Commented:
Peter:

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

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 5
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now