Solved

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

Posted on 2003-11-03
6
331 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 3

Expert Comment

by:NBrownoh
Comment Utility
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
Comment Utility
Thank you!  That worked perfectly!
0
 
LVL 5

Expert Comment

by:fantasy1001
Comment Utility
darkshadow,

thanks for that.
~ fantasy ~
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article will show, step by step, how to integrate R code into a R Sweave document
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

772 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

13 Experts available now in Live!

Get 1:1 Help Now