{"action":"created","issue":{"url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/400","labels_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/400/labels{/name}","comments_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/400/comments","events_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/400/events","html_url":"https://github.com/nodemcu/nodemcu-firmware/issues/400","id":73496709,"number":400,"title":"problem with net.socket:send()","user":{"login":"bernardoaraujor","id":9698228,"avatar_url":"https://avatars.githubusercontent.com/u/9698228?v=3","gravatar_id":"","url":"https://api.github.com/users/bernardoaraujor","html_url":"https://github.com/bernardoaraujor","followers_url":"https://api.github.com/users/bernardoaraujor/followers","following_url":"https://api.github.com/users/bernardoaraujor/following{/other_user}","gists_url":"https://api.github.com/users/bernardoaraujor/gists{/gist_id}","starred_url":"https://api.github.com/users/bernardoaraujor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bernardoaraujor/subscriptions","organizations_url":"https://api.github.com/users/bernardoaraujor/orgs","repos_url":"https://api.github.com/users/bernardoaraujor/repos","events_url":"https://api.github.com/users/bernardoaraujor/events{/privacy}","received_events_url":"https://api.github.com/users/bernardoaraujor/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-05-06T02:56:39Z","updated_at":"2015-05-07T09:32:07Z","closed_at":"2015-05-06T15:49:20Z","body":"Hello.\r\n\r\nThis is the code I'm trying to run on my ESP8266.\r\nWhen I try to send packets outside the while loop, it works fine.\r\nBut the packets inside the loop are not being sent.\r\n\r\nAnyone has any tip on this issue?\r\n\r\n```lua\r\n-- Reading liquid flow rate using an ESP8266\r\n-- Code adapted by Bernardo Rodrigues \r\n--from PC Fan RPM code written by \r\n--Crenn@thebestcasescenario.com\r\n\r\ncount = 0\r\nconn=net.createConnection(net.TCP, false)\r\nconn:connect(8888,\"192.168.0.103\")\r\n\r\n--count interrupts\r\nfunction rpm()\r\n     count = count + 1\r\nend\r\n\r\n--enable interrupts\r\nfunction enInt()     \r\n     gpio.mode(6, gpio.INT)\r\n     gpio.trig(6, \"up\", rpm)\r\nend\r\n\r\n--disable interrupts\r\nfunction disInt()\r\n     gpio.mode(6, gpio.INPUT)\r\nend\r\n\r\nconsumption = 0\r\n\r\n--infinite loop\r\nwhile 1 do     \r\n     count = 0       --Set NbTops to 0 ready for calculations\r\n     enInt()             --Enable interrupts\r\n     tmr.delay(1000000)  --Wait 1 second\r\n     disInt()            --Disable interrupts\r\n     flux = (count * 60 / 7.5)\r\n     consumption = consumption + flux/36000\r\n\r\n     conn:send(consumption)\r\n     \r\n     print(flux .. \" L/hour\")\r\n     print(consumption .. \" L consumed\\r\\n\")\r\nend\r\n```"},"comment":{"url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/comments/99793081","html_url":"https://github.com/nodemcu/nodemcu-firmware/issues/400#issuecomment-99793081","issue_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/400","id":99793081,"user":{"login":"TerryE","id":690173,"avatar_url":"https://avatars.githubusercontent.com/u/690173?v=3","gravatar_id":"","url":"https://api.github.com/users/TerryE","html_url":"https://github.com/TerryE","followers_url":"https://api.github.com/users/TerryE/followers","following_url":"https://api.github.com/users/TerryE/following{/other_user}","gists_url":"https://api.github.com/users/TerryE/gists{/gist_id}","starred_url":"https://api.github.com/users/TerryE/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TerryE/subscriptions","organizations_url":"https://api.github.com/users/TerryE/orgs","repos_url":"https://api.github.com/users/TerryE/repos","events_url":"https://api.github.com/users/TerryE/events{/privacy}","received_events_url":"https://api.github.com/users/TerryE/received_events","type":"User","site_admin":false},"created_at":"2015-05-07T09:32:07Z","updated_at":"2015-05-07T09:32:07Z","body":"@bernardoaraujor, let me expand on drv53b6's comment.  The way that this is written you are pushing out a new send on the assumption that the server is consuming them at a fast enough rate.  This might not be the case.  TCP is an assured delivery stack, so if the listener isn't reading the packets at this 1/sec rate then the server is queue a fixed number before telling the client end to delay.  If this happens and your code doesn't then it can crash.\r\n\r\nSomething like an RPi on the same local network should handle 100x this, but *if* you want your code to be more robust then you need to consider how to handle this type of overrun.  One option would be to drop samples. E.g. set a flag before each send and use an `on(\"sent\")` event to clear it down.  Only send the next sample if the flag is clear. But again this isn't a topic for this issue list so I won't give any more detail here on this issue."}}