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

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

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

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
darkshadow88
Asked:
darkshadow88
1 Solution
 
monvelasquezCommented:
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
 
darkshadow88Author Commented:
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
 
fantasy1001Commented:
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
Industry Leaders: 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!

 
NBrownohCommented:
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
 
darkshadow88Author Commented:
Thank you!  That worked perfectly!
0
 
fantasy1001Commented:
darkshadow,

thanks for that.
~ fantasy ~
0

Featured Post

Industry Leaders: 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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now