Solved

File Transfer using mswinsock control

Posted on 2002-03-14
6
205 Views
Last Modified: 2013-11-20
Dear friends
I want to transfer a file thru a socket created with winsock control.  I am able to transfer only text files and I donno how to transfer other files (image files in specific).  Please let me know abt this as soon as possible.

-Venkataramanan
0
Comment
Question by:venkataramanan
  • 3
6 Comments
 
LVL 49

Expert Comment

by:DanRollins
ID: 6867429
The actions are identical.  If you can do one, you can do the other -- there is nothing that needs to be explained.

Describe what problem you are having.  Show the code that malfunctions and describe what it is doing that you would want it to do differently.

-- Dan
0
 

Author Comment

by:venkataramanan
ID: 6867610
Dear Don
The data to be sent thru a socket should be put into a variant.  For text files, i read some 10 characters as a BSTR and set the variant type to VT_BSTR and it is received in the other end in a variant and extracted from "pbstrVal" member of the variant.  If i try this for other file types, it is not received correctly at the other end.

For other file types Pls tell me to which member of  the variant i have to put the file contents (which are read as a BSTR)and from which member I have to extract in the recieving end.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6868622
BSTR can contain binary data.  Just read chinks of data from the file and send it sa you have been.  When you receive it, be sure to copy the BSTR data to a byte array rather than (for instance) a CString object.  A CString object will truncate the data at the first NULL (0x00) thaat it encounters.

Show the code that you are using when you receive the data and I will try to see what is malfunctioning.

-- Dan
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 100 total points
ID: 6868642
An alternative would be to convert the binary data into text before you send it and then convert the text to binary data when you receive it.  

One simple method is to convert each byte into two hex digits.  Another method is to base64 encode the entire file.  But since these options increase the size of the transmission, it would be best to try to keep the binary data as binary data.

-- Dan
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 10401876
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Accept DanRollins
Please leave any comments here within the next four days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

AndyAinscow
EE Cleanup Volunteer

0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

810 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