Note that there are some explanatory texts on larger screens.

plurals
  1. POPython: Sockets not working over LAN
    text
    copied!<p>I recently came back from vacation, and my basic python 2 socket server is now unable to communicate with clients over LAN. The server is on a mac, and the client is my raspberry pi or my windows 7 machine. I have simplified the server and client code here to give an example:</p> <p><strong>Server</strong></p> <pre><code>import socket from thread import * HOST = socket.gethostname() print HOST PORT = input ("Enter the PORT number (1 - 10,000)") s = socket.socket(socket.AF_INET, socket.SOCK_STREAM ) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) print "Socket Created" s.bind((HOST, PORT)) print "Socket Bind Complete" s.listen(10) print "Socket now listening" #Sending message to connected client #This only takes strings (words while True: #Wait to accept a connection - blocking call connection, addr = s.accept() print "Connection Established!" connection.send("Welcome to the server. Type something and hit enter\n") #loop so that function does not terminate and the thread does not end while True: #Receiving from client data = connection.recv(1024) if not data: break connection.sendall(data) print data connection.close() s.close() </code></pre> <p><strong>Client</strong></p> <pre><code>import socket #for sockets s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) print "Socket Created" #Get host and port info to connect host = raw_input("HOST &gt;&gt;&gt; ") port = 2468 s.connect((host, port)) while True: #Send some data to the remote server message = raw_input("&gt;&gt;&gt; ") #set the whole string s.sendall(message) reply = s.recv(1024) print reply </code></pre> <p><strong>Question</strong></p> <p>What is going on here? I am getting the local IP, but the scripts are still not able to communicate. Could it be an issue with the OS's?</p> <hr> <p><strong>MORE INFO</strong></p> <ol> <li><p>Pinging</p> <p>a. I was able to ping the PI from my Mac terminal:</p> <pre><code>PING raspberrypi (67.63.55.3): 56 data bytes 64 bytes from 67.63.55.3: icmp_seq=0 ttl=240 time=17.434 ms 64 bytes from 67.63.55.3: icmp_seq=1 ttl=240 time=18.180 ms 64 bytes from 67.63.55.3: icmp_seq=2 ttl=240 time=22.046 ms 64 bytes from 67.63.55.3: icmp_seq=3 ttl=240 time=25.124 ms 64 bytes from 67.63.55.3: icmp_seq=4 ttl=240 time=31.773 ms </code></pre> <p>b. My PI was not able to find the Mac as a host. I will see what I can do to remedy this.</p> <p>c. My PC was able to PING my mac. My Mac was able to ping my PC</p></li> <li><p>Firewall</p></li> </ol> <p>My Mac's Firewall is off. I will check on the [Raspberry Pi Stackexchange Site] to see if the PI has a firewall. </p> <p>I will add more info once I test my windows machine</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload