Home AMX User Forum AMX Technical Discussion

IP Port closing too fast

sling100sling100 Junior MemberPosts: 111

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!



  • richardhermanrichardherman not-so-junior member Posts: 310

    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.

  • sling100sling100 Junior Member Posts: 111

    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?


Sign In or Register to comment.