Arduino, python, pyserial and socket
Question: I am trying to write a simple webserver on an Arduino to test a few things,
but I couldn't find my Arduino with Ethernet on it.

"No worries" I thought, "I'll just write a socket server in python that acts
as a proxy for the serial connection".

    
    
    import socket
    import serial
    host = ''
    port = 8001
    buffSize= 1024
    serverSocket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    serverSocket.bind((host, port))
    serverSocket.listen(1)
    ser = serial.Serial('COM3', 115200, timeout=None, dsrdtr =False,rtscts =False,xonxoff =False)
    print "Listening..."
    send = ""
    while 1:
        conn, remoteAddr = serverSocket.accept()
        print "Connection...."
        data = conn.recv(buffSize)
        print "Recieved"
        ser.write("%s\n"%data)
        print "Sent"
        print "Attempting to get reply"
        while ser.inWaiting()>0:
                conn.send( ser.read())
        conn.close()
    serverSocket.close()
    

However, whatever I try, it seems that the connection made by the browser
resets randomly and I'd get multiple rows of data. And the script resets the
Arduino each time it connects or disconnects from the serial port. I tried
using RealTerm and I got a proper answer, but python and serialness is just a
mess.

Can anyone help me?


Answer: Use the
[tcp_serial_redirect.py](http://pyserial.svn.sourceforge.net/viewvc/%2acheckout%2a/pyserial/trunk/pyserial/examples/tcp_serial_redirect.py)
script in the PySerial documentation. Is all you need.

