socket open issue

18 views
Skip to first unread message

Tom Morrison

unread,
Jun 18, 2014, 8:52:42 AM6/18/14
to solde...@googlegroups.com
I've been using the SolderCore device in the field at many locations. We're pushing data to GroveStreams once per minute with great success.  However...

We seem to be having an issue with opening sockets at times and I don't know how to get a handle on the underlying problem.  It should be noted that another platform at the same site is not having any issues opening connections at the same pace.  I am not seeing any errors at the GroveStreams end of things.  This also happens when there is no other device at the location, so it's not a multi-device issue.

In order to identify the problem, I created a simple program to repeatedly open & close sockets.  The socket number climbs with every open and after a couple dozen errors out with a negative return.  Is there anyway to identify the underlying cause so I can modify my program appropriately?

Here's my test program:

   10 UPDATEPERIOD = 2000
   20 '
   30 TIMER1 = TIMER
   40 '
   50 REPEAT
   60   IF(TIMER - TIMER1) > UPDATEPERIOD THEN
   70     TIMER1 = TIMER
   80     T = SOCKET("grovestreams.com", 80)
   90     PRINT "socket call return T: " + STR T
  100     PRINT "socket call returns report(): " + REPORT(T)
  110     IF(T < 0) THEN
  120       PRINT "socket call failed"
  130       RETURN
  140     ENDIF
  150     CLOSE T
  160   ENDIF
  170 UNTIL(1 = 0)
  180 '
  190 '

Is there a better way to structure this repeated call?  As stated above, I'm opening the socket once per minute.

Tom Morrison

unread,
Jun 18, 2014, 9:33:27 AM6/18/14
to solde...@googlegroups.com
BTW, the error code when it fails to successfully open a socket is: -3566.  I have no idea what means

Also...I see my code was a bit buggy, so I cleaned it up a touch:

   10 UPDATEPERIOD = 1000
   20 '
   30 TIMER1 = TIMER
   40 '
   50 REPEAT
   60   IF(TIMER - TIMER1) > UPDATEPERIOD THEN
   70     TIMER1 = TIMER
   80     T = SOCKET("grovestreams.com", 80)
   90     PRINT "socket call return T: " + STR T
  100     PRINT "socket call returns report(): " + REPORT(T)
  110     IF(T < 0) THEN
  120       PRINT "socket call failed"
  130       VDU 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7
  140     ELSE
  150       CLOSE T
  160     ENDIF
  170   ENDIF
  180 UNTIL(1 = 0)
  190 '
  200 '

Cam

unread,
Jun 18, 2014, 10:20:24 AM6/18/14
to solde...@googlegroups.com

Hi Tom,

 

This worked for me…. insert:

 

EJECT : REBOOT 'restart on error

 

When you test for a successful open socket and fail….. need autorun configured of course.

 

Cheers.

--
--
You received this message because you are subscribed to the Google
Groups "SolderCore" group http://groups.google.com/group/soldercore?hl=en

---
You received this message because you are subscribed to the Google Groups "SolderCore" group.
To unsubscribe from this group and stop receiving emails from it, send an email to soldercore+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tom Morrison

unread,
Jun 18, 2014, 10:30:51 AM6/18/14
to solde...@googlegroups.com, cya...@googlemail.com
It's often the case that the socket call after the failure is successful and we're on our way.  In my production code, I test for 15 successive failures and then reboot.

So....
1)  Are you recommending I reboot if I EVER get a failure status on an attempt to open a socket and
2)  Why the EJECT?  All I'm doing currently is a REBOOT
3)  Is the syntax exactly as you coded it (with a colon) EJECT : REBOOT

Yes, I do have AUTORUN configured already.  

Sorry for being a bit dense.

CoreBASIC Wizard

unread,
Jun 18, 2014, 2:55:16 PM6/18/14
to solde...@googlegroups.com, cya...@googlemail.com
Sockets remain open for about 15s after close in the FIN-WAIT-2 state (IIRC).  This is to stop stray packets on the network coming around and being directed to an open TCP connection.  (Use Google about this...)

Now, the thing is, there are a finite number of sockets.  Just hammering the socket system to open them again and again is a problem, the socket won't recycle until it has timed out.

So, just wait a few seconds and see if you can open the socket again.  And make sure that you do close them!

-- Paul.

Tom Morrison

unread,
Jun 18, 2014, 3:02:31 PM6/18/14
to solde...@googlegroups.com, cya...@googlemail.com
Hi Paul,

With regard to my production system, it tries to open a socket once per minute.  If it fails, it merely increments a counter and waits for aother minute (the "big loop").  If it successfully opens a socket, it resets the counter to 0.  If the counter ever gets to 15, which would equate to 15 successive attempts over 15 minutes, it calls a REBOOT of the SolderCore.  Does this make sense or would your recommend changing this approach?

Thanks,
Tom

Paul Curtis

unread,
Jun 18, 2014, 3:03:45 PM6/18/14
to solde...@googlegroups.com, cya...@googlemail.com
Err, I would say that sounds a little buggy.  :-(

I’d leave the approach you have.  I’m surprised it happens.  Debugging network stuff is really, really hard.  :-(

— Paul.

Tom Morrison

unread,
Jun 18, 2014, 3:31:20 PM6/18/14
to solde...@googlegroups.com, cya...@googlemail.com
Hmmm...you start by saying that sounds a little buggy and then you say I should leave the approach I have.  I'm sorry, but I'm confused, unless the "buggy" does not refer to my code.

What I'm seeing is occasional missing updates to GroveStreams (cloud service).  Now and then I'll see a whole bunch of them - say for 45 minutes.  I'm inclined to leave my code "as is" unless you feel I should more aggressively reboot if/when I see a failed open socket attempt. 

Paul Curtis

unread,
Jun 18, 2014, 4:44:40 PM6/18/14
to solde...@googlegroups.com, cya...@googlemail.com
On 18 Jun 2014, at 20:31, Tom Morrison <ctmor...@me.com> wrote:

Hmmm...you start by saying that sounds a little buggy and then you say I should leave the approach I have.  I'm sorry, but I'm confused, unless the "buggy" does not refer to my code.

That’s right, seems a lift;e buggy in the IP stack.


What I'm seeing is occasional missing updates to GroveStreams (cloud service).  Now and then I'll see a whole bunch of them - say for 45 minutes.  I'm inclined to leave my code "as is" unless you feel I should more aggressively reboot if/when I see a failed open socket attempt. 


I wouldn’t reboot all the time.  It could be the DNS lookup that failed!

— Paul.

Reply all
Reply to author
Forward
0 new messages