Python: Sockets funktioniert nicht über LAN

Ich kam vor kurzem aus dem Urlaub zurück, und mein basic-python 2-socket-server jetzt nicht für die Kommunikation mit clients über LAN. Der server ist auf einem mac, und der client ist mein raspberry pi oder meine windows 7-Maschine. Ich habe vereinfacht die server-und client-code hier, um ein Beispiel zu geben:

Server

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()

Client

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 >>>   ")
port = 2468
s.connect((host, port))


while True:   
    #Send some data to the remote server
    message = raw_input(">>>  ")

    #set the whole string
    s.sendall(message)


    reply = s.recv(1024)
    print reply

Frage

Was ist hier Los? Ich bin immer die lokale IP, aber die Skripte sind noch nicht in der Lage zu kommunizieren. Könnte es ein Problem mit dem Betriebssystem?


MEHR INFO

  1. Ping

    ein. Ich war in der Lage, die ping-PI von meinem Mac terminal:

    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

    b. Meine PI war nicht in der Lage zu finden, die Mac als host. Ich werde sehen, was ich tun kann, um Abhilfe zu schaffen.

    c. Mein PC war in der Lage zu PINGEN meinem mac. Mein Mac war in der Lage, ping mein PC

  2. Firewall

Mein Mac Firewall ist aus. Ich werde prüfen, auf die [Raspberry Pi Stackexchange Seite] um zu sehen, ob der PI hat eine firewall.

Werde ich hinzufügen, mehr info sobald ich test meine windows-Maschine

  • Können Sie ping für den anderen Maschinen? SSH Sie? Werden Ihre IP-Adressen statisch oder dynamisch?
  • Nicht sicher über IP ' s (ich weiß, dass meine externe dynamische) Ping-info wurde Hinzugefügt.
  • Unter Linux zuo maz verboten, das binden an einen port kleiner als 1024, wenn zou sind nicht superuser.
InformationsquelleAutor xxmbabanexx | 2013-03-25
Schreibe einen Kommentar