-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"readString" not returning everything (FTP) #176
Comments
Found the problem: The solution: Code:
|
Consider submitting a pull request with this change... If you do, one required change you'll have to make though is to default slow to false to ensure backwards compatibility with existing users. As it stands right now, it'll probably break somebody since the way you've got it coded, you've changed the signature of the readString() function. The other thing to consider is making the timeout value a parameter as well as the maxcount and maxnilcount_ again, with default values. The other alternative is to add the functionality as an overloaded version of the current function. You could eliminate the slow parameter and add a timeout parameter and the other counts, for example:
Let me know if you have any questions or need help submitting a pull request. Thanks. |
Sorry, I have no idea how to commit via git. If someone should come across the same problem, they can just use this code. |
I'm still using the library and it looks like not only reading text is affected, images downloaded with It's not possible not change that function because of the protocol, so I created a new one, using basically the same code as above, except that it appends to |
@Nathipha Could you make a Pull Request for both issues? It would be an interesting features to have in case of slow connection. Let us know if you need any help to setup the process. |
@mbarnach |
Would that be OK if I do it for you? I will integrate your changes into a pull request and submit it here. |
Issue: Kitura#176 Idea from @Nathipha
@mbarnach Sure, go ahead. I'm currently not at the mac but I can post the other function (for the data one) here later too. |
Thanks. Could you have a look at #201 ? |
Here's my the other edited function:
I was just testing it with 9mb images but the first call never returns more than 430kb, so looks like the server I'm testing it with is especially slow - or maybe my internet is too slow and it stops receiving more data after a certain amount of time (is that a thing?). I was only able to get all the data by looping over the function until it retuns 0 bytes (using the default "stream" mode, so it closes the data socket and from then on only returns 0 bytes), which doesn't necessarily look like the best solution. Your commit looks pretty similar and it'll probably give the same result unless I set |
Hi @Nathipha thanks for the detailed description of the problem. And thanks @mbarnach for expanding and submitting a PR. I added more detailed comments there, but just for continuity, I'll put my suggestion here as well. The short of it is that you're not guaranteed of data length in socket calls. So I believe your FTP application should do something like this:
It's a little bit of work, but it's typical of what I've had to do when working with sockets at a low level. This should work in the case of blocking or non-blocking sockets. If you're attempting to write an FTP server that can support multiple clients, then you'll definitely want to go the non-blocking route. |
@dannys42
This is what I added as a quick fix before I left a week ago because even though downloading data was more successful with the changes I made to the library itself, it still doesn't come close to finishing every time (as mentioned in my last post) and I'll be honest, I don't know what's the reason for that, if it's the timeout, the server, my internet connection, or simply the way FTP works. |
The general idea is correct, but if you're trying to make a TCP server that can listen and respond to multiple clients, that isn't usually the way you structure it. I'll see if I can work out an example, but it might take me a while before I can get to it. Just curious, have you worked with TCP sockets in other languages before? |
@dannys42 Edit: I changed |
Thanks @Nathipha, I can sympathize with wanting to get your FTP server done and not having to dig too far into BlueSocket. For what it's worth, this is pretty typical behavior for low-level sockets. Reading your edit, I believe what you're doing now in your I managed to write some tests over the weekend to confirm whether or not there are any issues in BlueSocket and more thoroughly stress test it in a streaming situation. I did not find any technical issues. However in writing the tests I did have to add I plan to do a bit more refactoring and adding some more documentation to make the logic easier to follow. But it might take me a few days to get to it. I pushed what I have so far into an open PR in case it helps you. |
First of all: Thanks for writing a library that works with an FTP server and is easy to use!
I created a new app in Xcode 10 with Swift 5 and the latest version of BlueSocket (installed via CocoaPod) to test it and I've come across a problem:
I can open a normal and a data socket to the FTP server and log in using
cmdsocket.write(from: "USER \(username)\r\n")
just fine (you can find a list of ftp codes here) butwhich should list the files and folders at the root only prints the very first one. It's working with a different server (e.g. "speedtest.tele2.net" is free to use for testing), so it looks like "my" server is too slow and/or the library is too fast (and possibly not waiting until the server is done?).
Is there a way to set some kind of timeout for that, e.g. if you don't get a result for the third time, stop reading, instead of stopping after the first try?
The text was updated successfully, but these errors were encountered: