Solved

How can I make sure a transfer through winsock is complete before trying to use the file?

Posted on 2003-11-03
6
335 Views
Last Modified: 2013-11-13
I wrote a program that will take the screenshot of a remote computer screen and send it to me over winsock.  The problem is, it tries to display the image before the transfer is complete.  On the server side, I have the following code:

keybd_event vbKeySnapshot, 1, 0&, 0&
SavePicture Clipboard.GetData(vbCFBitmap), "c:\sht.bmp"
Dim Efile As String
Open "c:\sht.bmp" For Binary As #1
Efile = Space(LOF(1))
Get #1, 1, Efile
Close #1
frmServer.tcpserver.SendData Efile

(plus the required function declarations), and on the client side, I have

tcpclient.GetData strdata
Open "c:\screenshot.bmp" For Binary As #1
Put #1, , vardata
Close #1
frmSShot.imgssht.Picture = LoadPicture("c:\screenshot.bmp")

the problem is, when it tries to load the picture, only a small portion of the file is present (4~8kB) out of 275kB or so, so an error occurs.  How can I make sure the entire file is transferred and written before displaying the picture?
0
Comment
Question by:darkshadow88
6 Comments
 
LVL 3

Expert Comment

by:monvelasquez
ID: 9676400
Try specifying the type and size of the data...
I know that there's a "bytesTotal" parameter on the DataArrival Event. you could use that

tcpclient.GetData strdata, vbString, bytesTotal.

____________
Raymond:\>_
0
 

Author Comment

by:darkshadow88
ID: 9676477
I tried that, and it doesn't work.  I noticed that the screenshot.bmp file that is generated is always either 4.27kB or 8.00kB; never more than that.  Could my problem have to do with limitations on string length, and if so, how could I get around it?
0
 
LVL 5

Accepted Solution

by:
fantasy1001 earned 175 total points
ID: 9676652
Here is an example of file transfer with progress bar indication. You should read at the server side, the event DataArrival
http://www.freevbcode.com/ShowCode.Asp?ID=906

~ fantasy ~
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 3

Expert Comment

by:NBrownoh
ID: 9677119
what you should do is this:
for the sending program define a boolean = true when you start sending the picture
then on the winsock_sendcomplete sub do an if then statement

If bPicSending = true then
  winsock.send "Complete"
  bPicSending = false
end if

then on the recieving side wait until you get that "Complete" message or something similar to display the image.
0
 

Author Comment

by:darkshadow88
ID: 9680389
Thank you!  That worked perfectly!
0
 
LVL 5

Expert Comment

by:fantasy1001
ID: 9683152
darkshadow,

thanks for that.
~ fantasy ~
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

830 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