connect two raspberry pi via ethernet cable
Question: I am using python to connect two raspberry pi via serial port. one pi will
send data to another pi. and another pi will do some specfic task depending on
received data. can i use ethernet port for this function? Is there any
function similar to serial.read() and serial.available() in case of ethernet
port.

I wrote the simple server program

    
    
    import socket
    s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    host=socket.gethostname()
    port=12345
    s.bind((host, port))
    s.listen(5)
    while True:
        c, addr = s.accept()
        print 'got connection from',addr
        c.send('Thank you for connecting')
    
        c.close()
    

and client program is

    
    
    import socket               
    
    s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)        
    host = socket.gethostname() 
    port = 12345               
    s.connect((host, port))
    print s.recv(1024)
    s.close                    
    

error is no connection is made because target machine actively refuse it. what
is my mistake?


Answer: Yes, you can use ethernet for this purpose. You can create a
[TCP](https://wiki.python.org/moin/TcpCommunication) connection between the
two machines. Much like a serial connection, this will give you a
bidrectional, byte stream.

