Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy File without shell 1

Status
Not open for further replies.

Mengbillar

Programmer
Jan 13, 2003
32
0
0
DE
I want to copy (and send via winsock) a file, so i cannot use any of the 'normal' copy methods. what i tried is this

Open <file> For Binary Lock Write As #1
Dim temp As String * 1, length As Long, a As Long
length = LOF(1)
a = 0
While a < length
Get #1, , temp
Winsock1.SendData temp
a = a + 1
Wend
Close

This kinda works, i am able to recieve and build the file at the other end, but the file itsself turned into garbage. any idea what wrong/how i can accomplish my goal in a better way?
 
I'm not familiar with the Windows sockets, but I've used some third party control once to communicate with a server and that control was not able to send some binary characters, like for instance a binary 0 or 1. It might be that your file contains such characters and that winsock cannot handle those characters. What I did was convert a string to HEX characters before sending them and reconvert them back at the receiver side. This worked fine.
Greetings,
Rick
 
This might be it.... SO how do i (de)convert strings into hex?
 
Use this:

a$ = &quot;B0&quot;
Value = Val(&quot;&h&quot; & a$ & &quot;&&quot;)

Works great.
 
I finally found another sollution which works great too. I am not sending the character itsself, but the corresponding ascii number
 
This has the disadvantage that you use three characters to transmit one (eg. chr(0) becomes 000). That will reduce the theoretical technical transferrate from full to 1/3 of the original. I would go for the hex transmit. (0 becomes 00)
 
Good answer Iwarez (you get a star for this)... even if it is only a small file, there's no sense in using extra bandwidth when you don't have to.

Understandably, some people might not know that Hexadecimal is intentionally used as a shorthand for binary. A binary 'word' is 8 bits long (8 bits in a byte). But when transmitting binary (0's and 1's) it takes 8 bytes to represent what should be only one byte. With hexadecimal, we can shorten this to two bytes.

Tuna - It's fat free until you add the Mayo!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top