TCP Server Help

Hi all,
Currently working on a project with a TCP Server and could use some help. The reliability of the core’s connections are very iffy right now and I could use some help from experts… Below is my python code

        #buf is our output file
        spark_core = '10.0.0.7'
        sc_port = 17061
        BUFFER_SIZE = 2048
        #just about the right amount of time to wait in between sending
        perfect_time = 0.015
        #print buf
        print "Trying to socket and connect"
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        for x in xrange(2):
            try:
                s.connect((spark_core, sc_port))
                print "connected"
                for x in buf:
                    s.send(x)
                    time.sleep(perfect_time)
                print "Done sending"
                s.close()
                break
            except:
                print "Failure"

Here is a pastebin of my Core code: http://pastebin.com/YYw0kzct

The output I get is usually like:
""“
updating
Trying to socket and connect
connected
Done sending
updating
Trying to socket and connect
connected
Done sending
updating
… (anywhere from 10 seconds to 5 minutes later) …
Trying to socket and connect
Failure
Failure
updating
Trying to socket and connect
Failure
Failure
updating
Trying to socket and connect
Failure
Failure
…(continues in this fashion, and most of the time results in the Core rebooting)…
”""

Edit: When the core does reboot, it usually takes a few attempts to actually get a connection again.
Forgot to mention, I am also having trouble flashing after a connection has already been made to the device. I have to turn it off and on again then try to reflash.

It looks like I’m having more issues. My Core will randomly shut off when I’m not sending it messages and has to be restarted constantly to make another connection to the rpi.

Maybe if you are having trouble with the Spark side, you could post that code instead?

I would start by making it work with port 80 and web browser or curl and then move to python.

Spark Code is underneath python code: http://pastebin.com/YYw0kzct

any suggestions? all the problems I’ve been having lately with the Core have been slowing down my project alot

Hello, I’ve been struggling as well, with a webserver based on the TCP Server class. Same behaviour, such as time-outs ant frequent spontanious reboots. Playing with delays to resolve things didn’t really work and adding code only seemed to make my core less stable. Eventually I rebuild my project using the Webserver library. The reboots were not resolved, but I noticed that the cloud connection made everything less stable. Reboots occurred within minutes and as meaured often there was a 60 second timeout. Now I added a disconnect feature and without the cloud my black Spark Core appears much more stable and is happily breathing green and still showing the heartbeat blink I added to my loop() after a whole night of running.

My suggestion: try using the new semi-automatic mode to see if stability improves when not being connected to the cloud.