Solved

File Transfer using mswinsock control

Posted on 2002-03-14
6
203 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Change owner from userA to server Local Administrators 7 51
if loop in java 3 114
viewing source code from eclipse 13 74
Hibernate methods 2 58
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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 discusses moving either the default database or any database to a new volume.

759 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

22 Experts available now in Live!

Get 1:1 Help Now