I want to develop two apps, the client and server.
How do I send files (doc,docx,pdf) over TCPSocket?
Maybe start reading about Socket functions in Xojo and look into the example projects coming with Xojo. See networking folder.
I just happened to need to do the exact same thing today and found your question. Here is what I did; I hope it is of some use to you.
On the sending end (the client, I presume) open the file as a BinaryStream and write it. On the receiving end, read it all in and then save it, again using a BinaryStream.
My simplistic test code:
Sender (sckSend is already connected):
' Send a file
var fldSource As FolderItem
fldSource = GetFolderItem("<your file path here>")
if (fldSource <> Nil) then
Try
Var stream As BinaryStream
stream = BinaryStream.Open(fldSource, False)
Do
sckSend.Write stream.Read(255)
Loop Until stream.EndOfFile
stream.Close
end
End If
sckSend.Flush
Receiver (DataAvailable event for the socket):
strMessage = me.ReadAll
var fldSource As FolderItem
fldSource = GetFolderItem("<your destination file here>")
Try
Var stream As BinaryStream
stream = BinaryStream.Create(fldSource, True)
stream.Write strMessage
stream.Close
end
2 Likes