title: Raspberry PI Server/Client Socket in Python
body: <p>I am trying to set up a Python socket between my Raspberry Pi (running Raspbian) and my Macbook Pro (running Mavericks).</p>
  
  <p>Both devices are connected to the same WiFi network in my appt.  I run the server code on my RPi and then the client code on my Macbook (I have also tried the reverse).  I think that I am missing a set up step because the code I am using I found on multiple sites, so I assume it works.  I also checked that my Macbook has firewall turned off.</p>
  
  <p><strong>Server Code:</strong></p>
  
  <pre><code>from socket import *
  
  host = "127.0.0.1"
  
  print host
  
  port = 7777
  
  s = socket(AF_INET, SOCK_STREAM)
  
  print "Socket Made"
  
  s.bind((host,port))
  
  print "Socket Bound"
  
  s.listen(5)
  
  print "Listening for connections..."
  
  q,addr = s.accept()
  
  data = raw_input("Enter data to be sent: ")
  
  q.send(data)  
  </code></pre>
  
  <p><strong>Client Code:</strong></p>
  
  <pre><code>from socket import *
  
  host = "127.0.0.1"
  
  print host
  
  port=4446
  
  s=socket(AF_INET, SOCK_STREAM)
  
  print "socket made"
  
  s.connect((host,port))
  
  print "socket connected!!!"
  
  msg=s.recv(1024)
  
  print "Message from server : " + msg
  </code></pre>
  
  <p><strong>I get the error:</strong></p>
  
  <blockquote>
  <pre><code>Traceback (most recent call last):
    File "TCPclient.py", line 9, in &lt;module&gt;
      s.connect((host,port))         
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py",
  </code></pre>
    
    <p>line 224, in meth
            return getattr(self._sock,name)(*args)
        socket.error: [Errno 61] Connection refused</p>
  </blockquote>
  
  <p><strong>My process for executing the code is:</strong></p>
  
  <ul>
  <li><p>type "python TCPserver.py" into RPi terminal</p></li>
  <li><p>type "python TCPclient.py into Macbook terminal</p></li>
  </ul>
  
  <p>Then I receive the error message on my Macbook, no error on the RPi</p>
  
  <p><strong>My questions are:</strong></p>
  
  <ol>
  <li>Is 127.0.0.1 the proper input for "host"? (please note I also tried "localhost")</li>
  <li>Does the input for host have to be the same for the client and server code?</li>
  <li>Should the RPi and Macbook both be connected to the same WiFi network?</li>
  <li>Is there any set up that needs to be done on either the RPi or my Macbook in order for this to work (Please note my RPi is Model B, new, and I did not set up anything else on it before this)</li>
  <li>Do you know why I am receiving this error and how to fix it?</li>
  </ol>
  
  <p>Your help is greatly appreciated!!</p>