Сервер
Код: Выделить всё
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()
Код: Выделить всё
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
Что здесь происходит? Я получаю локальный IP-адрес, но сценарии по-прежнему не могут обмениваться данными. Может ли это быть проблема с операционной системой?
ДОПОЛНИТЕЛЬНАЯ ИНФОРМАЦИЯ
- Пингинг
а. Мне удалось проверить связь с PI с моего терминала Mac:
б. Мой PI не смог найти Mac в качестве хоста. Я посмотрю, что можно сделать, чтобы это исправить.Код: Выделить всё
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
c. Мой компьютер смог выполнить PING мой Mac. Мой Mac смог проверить связь с моим компьютером. - Брандмауэр
Я добавлю дополнительную информацию, как только проверю свою машину с Windows
Подробнее здесь: https://stackoverflow.com/questions/156 ... g-over-lan
Мобильная версия