IP Port closing too fast
I've got a bunch of devices that communicate via HTTP using server ports on the processor. They send me a 'connection: close' as part of the header, so I send a 'HTTP/1.1 200 OK' back, shut the port and reopen it ready for the next message. All good.
The issue is that sometimes the client closes the port instead of waiting for me to respond - and often this is so fast that my 'send string' fails, despite the port still indicating it is 'online'. Diagnostics below - you can see that the send_string fails before the offline event fires. I've quantified the send_string so it only sends if the port is online, but it still fails as the offline event hasn't been received.
Line 458 2019-05-21 (07:29:58):: CIpEvent::OnLine 0:50:1
Line 459 2019-05-21 (07:29:58):: SendString to socket-local port (50) invalid
Line 460 2019-05-21 (07:29:58):: CIpEvent::OffLine 0:50:1
Line 461 2019-05-21 (07:29:58):: CIpEvent::OnError 0:50:1
Line 462 2019-05-21 (07:29:58):: CIpEvent::OnLine 0:50:1
Line 463 2019-05-21 (07:29:58):: SendString to socket-local port (50) invalid
Line 464 2019-05-21 (07:29:58):: CIpEvent::OffLine 0:50:1
Line 465 2019-05-21 (07:29:58):: CIpEvent::OnError 0:50:1
Line 466 2019-05-21 (07:29:59):: CIpEvent::OnLine 0:50:1
Line 467 2019-05-21 (07:29:59):: SendString to socket-local port (50) invalid
Line 468 2019-05-21 (07:29:59):: CIpEvent::OffLine 0:50:1
I suppose no real harm is done from this, but it's not great practice and certainly any other programmer is going to look at it and go 'ohh that's bad'. Anyone else experience this? Other than putting a 'wait' in before trying to send the 200 OK response I'm not sure what else I can do.
Any and all advice appreciated as always!
Simon
Comments
-
Some random remarks, not an answer...:
you can turn on milliseconds for notifications and or diagnostics in: 'settings' > 'preferences' > 'diagnostics'
it will give you a better idea of response times. Although I'm not sure I would trust diagnostics to be in the exact order you expect, especially when things get into the milliseconds response range.I noticed you use port 50 for the device. While valid, every port upto 50 will consume some resources, even if not used. So if you don't actually use so many ip devices, it would probably be a good idea to lower the port number.
-
I am using 50 ports :-) Well 45 actually as the first device on is port 5.
I'll turn the milliseconds on - don't think I've tried that, so thanks. It may help to show the status order, although I guess it won't help in terms of the offline event firing after its actually happened. I'm thinking it's because the function that sends the string is quite long, so if the port drops during the function running it won't actually show until afterwards as the processor is single threaded?
Simon
Categories
- All Categories
- 2.5K AMX General Discussion
- 922 AMX Technical Discussion
- 514 AMX Hardware
- 502 AMX Control Products
- 3 AMX Video Distribution Products
- 9 AMX Networked AV (SVSI) Products
- AMX Workspace & Collaboration Products
- 3.4K AMX Software
- 151 AMX Resource Management Suite Software
- 386 AMX Design Tools
- 2.4K NetLinx Studio
- 135 Duet/Cafe Duet
- 248 NetLinx Modules & Duet Modules
- 57 AMX RPM Forum
- 228 MODPEDIA - The Public Repository of Modules for Everyone
- 943 AMX Specialty Forums
- 2.6K AMXForums Archive
- 2.6K AMXForums Archive Threads
- 1.5K AMX Hardware
- 432 AMX Applications and Solutions
- 249 Residential Forum
- 182 Tips and Tricks
- 146 AMX Website/Forums