file transfer over sockets
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
file transfer over sockets
I've never done anything with sockets before so I've started playing with the chat server and client stacks a little. One thing I wanted to try and tackle was file transfer. I can send small files, but I can see as the files get bigger I'm probably going to need to send/receive small chunks of the file. I haven't found anything in searching, but are there any existing stacks or code examples of this around? baring that are there any best practices for this, like best bunk sizes and the best way to write the loop scripts for the read and write?
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: file transfer over sockets
You could start from here:
Use "Sample stacks" from the LC toolbar. Search for sockets (simplest socket client/ simplest socket server).
There is no *overall* optimal chunk size, depends on server, client and object to transfer.
Use "Sample stacks" from the LC toolbar. Search for sockets (simplest socket client/ simplest socket server).
There is no *overall* optimal chunk size, depends on server, client and object to transfer.
shiftLock happens
Re: file transfer over sockets
Here a guide: http://livecodeitalia.blogspot.it/2017/08/sockets.htmlwindowsLC wrote: ↑Wed Dec 27, 2017 5:44 amI've never done anything with sockets before so I've started playing with the chat server and client stacks a little. One thing I wanted to try and tackle was file transfer. I can send small files, but I can see as the files get bigger I'm probably going to need to send/receive small chunks of the file. I haven't found anything in searching, but are there any existing stacks or code examples of this around? baring that are there any best practices for this, like best bunk sizes and the best way to write the loop scripts for the read and write?
There is the translate button in the top left of the page.
Regarding size, in a private LAN, you should not have any problem with any size.
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
Re: file transfer over sockets
Thanks for all the replies.
I have been able to make the client and the server following the demo apps. I am able to send and receive the small chat messages just fine. What I can't seem to do is send a binary file across. What I have tried:
I've opened an image file on the client side for binary read and read it into a field. Then I try to write that field to the socket.
On the server side, I am reading from the socket and putting that into a field. I tried "until EOF" on the read but not enough data appears to be read and put into the field. I tried looping it with more reads "until EOF" and I get more data but It doesn't seem to match the data in the client field.
I've looked through all the suggested info but I see no info on sending files over sockets, just text, and chat which I already can do.
UPDATE: I am now able to get the data across and the two fields match by using until return instead of EOF. Other then the word false being added (not sure what that is about). I will now try and write the data to a file.
I have been able to make the client and the server following the demo apps. I am able to send and receive the small chat messages just fine. What I can't seem to do is send a binary file across. What I have tried:
I've opened an image file on the client side for binary read and read it into a field. Then I try to write that field to the socket.
On the server side, I am reading from the socket and putting that into a field. I tried "until EOF" on the read but not enough data appears to be read and put into the field. I tried looping it with more reads "until EOF" and I get more data but It doesn't seem to match the data in the client field.
I've looked through all the suggested info but I see no info on sending files over sockets, just text, and chat which I already can do.
UPDATE: I am now able to get the data across and the two fields match by using until return instead of EOF. Other then the word false being added (not sure what that is about). I will now try and write the data to a file.
Last edited by windowsLC on Wed Dec 27, 2017 11:29 pm, edited 1 time in total.
Re: file transfer over sockets
I believe you could manipulate pictures by using textData (see dictionary)
Maybe that will allow you to xfer the picture, and control how much of it is sent at a time (not sure, never tried it).Fully Supported Formats
Setting the text to one of these formats displays the image as expected and sets the paintCompression to the correct type automatically. The data is also preserved meaning that getting the text returns the original data unchanged.
- GIF (All platforms)
- JPEG (All platforms)
- PNG (All platforms)
- WMF (Windows only - Windows Metafile)
- EMF (Windows only - Windows Enhanced Metafile)
Re: file transfer over sockets
Thanks, bogs, I posted an update to my previous post before I saw your reply.
Your info looks good for images I'll look into it. I've also thought about base64 encoding first, but right now I'm going with the premise that if it is just over LAN I shouldn't need to worry about chunk size yet (which I think I found on a C++ forum that the TCP limit of 1500 is best). Right now I'm going see if my received data will write to a file.
Your info looks good for images I'll look into it. I've also thought about base64 encoding first, but right now I'm going with the premise that if it is just over LAN I shouldn't need to worry about chunk size yet (which I think I found on a C++ forum that the TCP limit of 1500 is best). Right now I'm going see if my received data will write to a file.
Re: file transfer over sockets
You might also look at BvG's sample chat client (I think user samples). Although I never used it, his stuff is always good to parse
Re: file transfer over sockets
Amazed! I got it to work. I can send the file from client to server and the server can create the file.
I'm definitely going to have to figure out something for larger files though, the overhead of the current method is a lot I think because of putting the whole file in memory, better to read and write in chunks, I think
I'm definitely going to have to figure out something for larger files though, the overhead of the current method is a lot I think because of putting the whole file in memory, better to read and write in chunks, I think
-
- VIP Livecode Opensource Backer
- Posts: 9801
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: file transfer over sockets
Rather than invent your own protocol, have you considered HTTP?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: file transfer over sockets
I'm open to it FourthWorld and thought about it. Just not really sure how to implement HTTP in this LAN server to client setup.
-
- VIP Livecode Opensource Backer
- Posts: 9801
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: file transfer over sockets
What else is on the server? Do you have Apache or Lighttpd there?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: file transfer over sockets
Fourthworld, I've created a server and a client program like in all the Chat demo stacks around. I will need file distribution abilities along with the chat which is what I have started with sending the files over the sockets. the use case for this is purely over a local LAN and I won't have an existing web server at my disposal.
I think I can guess where you are going with this and I have thought about a small web server I can run from shell but ideally, I would like to keep this purely livecode as I started this project as a way to get my self back into using livecode.
I do think I remember people have created http servers in livecode before, that might interest me if I could create one that the only purpose is to allow the download of the files I need to distribute.
I think I can guess where you are going with this and I have thought about a small web server I can run from shell but ideally, I would like to keep this purely livecode as I started this project as a way to get my self back into using livecode.
I do think I remember people have created http servers in livecode before, that might interest me if I could create one that the only purpose is to allow the download of the files I need to distribute.
Re: file transfer over sockets
Hello windowsLC...Did you find the solution? We are working on this also. We need to send a 1MB file over sockets.