title: TCP Connection refused in Streaming Context of apache Spark, python
body: <p>I wish to receive data from an android application "IMU+GPS sensorstream" link : 
  <a href="https://play.google.com/store/apps/details?id=de.lorenz_fenster.sensorstreamgps&amp;hl=en" rel="nofollow noreferrer">https://play.google.com/store/apps/details?id=de.lorenz_fenster.sensorstreamgps&amp;hl=en</a>    </p>
  
  <p>I need to make a spark Dstream out of it. But I receive below error. </p>
  
  <pre><code>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)
  </code></pre>
  
  <p><b> I have forwarded port '5555' which is in use. </b>    </p>
  
  <p>If I use below program to receive the data it is <b>successful</b>. 
  Hence in a similar way how can I receive data to make it a spark stream. </p>
  
  <p>Please help, stuck with it for more than a week now!!. </p>
  
  <pre><code>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()
  </code></pre>