Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2003-11-03
6
Medium Priority
?
338 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 700 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

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.

Question has a verified solution.

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

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.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
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…

715 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