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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CAN ONE USE WINSOCK TO TRANSFER FILES

Status
Not open for further replies.

TrueCode

MIS
Joined
Sep 30, 2003
Messages
71
Location
LC
I would like to be able to transfer files from one machine to another through and Dialup Peer to Peer arrangement. The two computers are not FTP Servers, so FTP is not an option. Is there a way to send a file across with WINSOCK TCP OR UDP?

------------------------------------->

"I have sought your assistance on this matter because I have exhausted all the help that I can find. You are free to direct me to other source of help"
 
TrueCode,

Yes, you can do it with TCP.

Right click on the Winsock control that's dropped on a VFP form and choose Help. This should bring up the help for the winsock control and guide you through getting started.

Andy
 
See the answers in your thread184-682221

What are you trying to do so far that isn't working?
 
wgcs
I read through that thread and I am wondering how to accumulate the chunks as they come?

Is it something like:
PROCEDURE dataarival
....

Local eThisChunk as Variant

oWinsock.getdata(@eThisChunk)
eDataRecvd = eDataRecvd + eThisChunk


Then do an FCREATE() AND FPUT()

TO create the received file....



------------------------------------->

"I have sought your assistance on this matter because I have exhausted all the help that I can find. You are free to direct me to other source of help"
 
TrueCode,

You're on the right track as far as accumulating the packets. I like to include the size of the message as the first 10 characters of the message so I know how much to expect. Then the rest of the message (file) follows after that. The receiver would then parse out the first 10 characters of the first packet and keep appending to the string until the size is reached.

The nice thing about TCP is that the packets are guaranteed to come in order. All that is handled at a lower level.

Here is example dataarrival code that hopefully illustrates what I'm saying (you'll have to figure out my custom properties):

*** ActiveX Control Event ***
LPARAMETERS bytestotal
LOCAL llFirstPacket, lcSize
*** First Packet of information
IF THIS.r_nReceiveSize = 0
llFirstPacket = .T.
THIS.r_cReceiveString = ""
ENDIF
lcString = REPL(CHR(0), bytestotal)
THIS.GetData(@lcString, 8, bytestotal)
IF llFirstPacket
lcSize = SUBSTR(lcString, 1, 10)
lcString = SUBSTR(lcString, 11)
llFirstPacket = .F.
THIS.r_nReceiveSize = VAL(lcSize)
ENDIF
THIS.r_cReceiveString = THIS.r_cReceiveString + lcString
IF LEN(THIS.r_cReceiveString) = THIS.r_nReceiveSize
** Full Message has been received.
THIS.r_nReceiveSize = 0
THIS.r_lPendingMessage = .T.
EXIT
ENDIF


Andy
 
Be sure you don't use FPUT() to re-create the file: FPUT() follows every write with a CRLF.

Instead, use FWRITE() if you are sending the received chunks directly to a file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top