Solved

send pictures through the winsock control

Posted on 1998-10-28
11
624 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
ID: 1442073
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
ID: 1442074
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
ID: 1442075
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
ID: 1442076
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
ID: 1442077
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:Chamberlain
ID: 1442078
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
ID: 1442079
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
ID: 1442080
Peter, please send me your solution
to the problem.

0
 
LVL 3

Author Comment

by:otroligafredde
ID: 1442081
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
ID: 1442082
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
ID: 1442083
Peter:

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

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

914 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

21 Experts available now in Live!

Get 1:1 Help Now