Skip to content
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

socket:send problem #964

Closed
Hellsy22 opened this issue Jan 21, 2016 · 3 comments
Closed

socket:send problem #964

Hellsy22 opened this issue Jan 21, 2016 · 3 comments

Comments

@Hellsy22
Copy link

Previously: #913
I was wrong, it's not on:receive problem - it's socket:send problem.

Bug example:

sk=net.createConnection(net.TCP, 0)
sk:on("connection", function (sck)
    sck:send("GET / HTTP/1.1\r\nHost: api.ipify.org\r\nConnection: close\r\nAccept: */*\r\n")
    sck:send("\r\n")
end)

sk:on("disconnection", function(sck) print "Disconnected\n" end);
sk:on("receive", function(sck, c)
    print("got: " .. c)
end)

sk:connect(80, "54.225.138.188")

if I change

sck:send("GET / HTTP/1.1\r\nHost: api.ipify.org\r\nConnection: close\r\nAccept: */*\r\n")
sck:send("\r\n")

to

sck:send("GET / HTTP/1.1\r\nHost: api.ipify.org\r\nConnection: close\r\nAccept: */*\r\n\r\n")

All be ok. On older (sep 2015) firmware both cases was ok.

I checked more:

sk=net.createConnection(net.TCP, 0)
sk:on("connection", function (sck)
    sck:send("first\r\n");
    sck:send("second\r\n")
    sck:send("third\r\n")
end)

sk:on("disconnection", function(sck) print "Disconnected\n" end);
sk:on("receive", function(sck, c)
    print("got: " .. c)
end)

sk:connect(8882, "10.101.10.1")

Result:

# nc -l -p 8882
nc: using stream socket
first

All consequent send was ignored.

@pjsg
Copy link
Member

pjsg commented Jan 21, 2016

Yes -- it turns out that with the later SDKs from espressif, you can only have one socket::send outstanding at once. This is really annoying. I worked around this by using coroutines. In my case, I was making an httpserver work, but the idea is the same.

You can take a look at https://github.com/marcoskirsch/nodemcu-httpserver for the stuff that I did (look in the commit log).

@devsaurus
Copy link
Member

This characteristic of the SDK is covered in the FAQ at https://nodemcu.readthedocs.org/en/dev/en/faq/#how-is-coding-for-the-esp8266-different-to-standard-lua Also see #730 for technical details.
Will be closed due to reasons stated in #719.

@Hellsy22
Copy link
Author

@pjsg, @devsaurus Thanks for the clarification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants