Socket stops communicating

Posted by user1392992 on Stack Overflow See other posts from Stack Overflow or by user1392992
Published on 2013-11-06T05:28:46Z Indexed on 2013/11/06 15:53 UTC
Read the original article Hit count: 132

I'm running python 2.7 code on a Raspberry Pi that receives serial data from an Arduino, processes it, and sends it to a Windows box over a wifi link. The Pi is wired to a Linksys router running in client bridge mode and that router connects over wifi to another Linksys router to which the Windows box is wired. The code in the Pi runs fine for some (apparently) random interval, and then the Pi becomes unreachable from the Windows box.

I'm running PUTTY on the the Windows machine to connect to the Pi and when the fail occurs I get a message saying there's been a network error and the Pi is not reachable. Pinging the Pi from the Windows machine works fine until the error, at which time it produces "Reply from 192.168.0.129: Destination host unreachable." The client bridge router to which the Pi is connected remains reachable.

I've got the networking code on the Pi wrapped in an exception handler, and when it fails it shows the following:

Ethernet problem:
Traceback (most recent call last): File "garage.py", line 108, in module
s.connect((host, port))
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
error: [Errno 113] No route to host
None

The relevant python code looks like:

import socket
import traceback
host = '192.168.0.129'  
port = 31415

in the setup, and after serial data has been processed:

try:
    bline = strline.encode('utf-8')
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((host, port))
    s.send(bline)
    s.close()
except:
    print "Ethernet problem: "
    print traceback.print_exc()

Where strline contains the processed data. As I said, this runs fine for a few hours more or less before failing. Any ideas?

EDIT: When PUTTY fails its error message is :Network Error: Software caused connection abort."

© Stack Overflow or respective owner

Related posts about python

Related posts about sockets