0
我想從一個Android應用程序「IMU + GPS sensorstream」鏈路接收數據: https://play.google.com/store/apps/details?id=de.lorenz_fenster.sensorstreamgps&hl=enTCP連接,蟒蛇
我需要一個火花DSTREAM出來。但我收到以下錯誤。
from pyspark import SparkContext
from pyspark.streaming import StreamingContext
spc = SparkContext(appName="testReceive")
stc = StreamingContext(spc, 5)
#Is there an error in below line?
lines = stc.socketTextStream("localhost" , 5555)
words = lines.flatMap(lambda line: line.split(" "))
pairs = words.map(lambda word: (word, 1))
wordCounts = pairs.reduceByKey(lambda x, y: x + y)
wordCounts.pprint()
stc.start()
stc.awaitTermination()
ERROR :
-------------------------------------------
Time: 2016-12-06 10:48:55
-------------------------------------------
16/12/06 10:48:55 WARN ReceiverSupervisorImpl: Restarting receiver with delay 2000 ms: Error connecting to localhost:5555
java.net.ConnectException: Connection refused (Connection refused)
我已轉發正在使用的端口'5555'。
如果我使用下面的程序來接收它成功數據。 因此以類似的方式我怎麼能接收數據,使之成爲火花流。
請幫幫忙,堅持了一個多星期更現在!。
import socket, traceback
host = ''
port = 5555
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
s.bind((host, port))
while True:
try:
message, address = s.recvfrom(8192)
message = message.decode()
data = message.split(",")
print(data)
except (KeyboardInterrupt, SystemExit):
raise
except:
traceback.print_exc()