0

I have a stream created at port 9999 of my computer. enter image description here

I have to implement DGIM Algorithm on it. However I am not able to read the bits in the Data stream one by one. Below is my code:

from pyspark import SparkContext
from pyspark.streaming import StreamingContext
import math
sc = SparkContext("local[2]", "NetworkWordCount")
ssc = StreamingContext(sc, 1)

when I use the following command I am able to print the stream in batches:

lines.pprint()
ssc.start()             # Start the computation
ssc.awaitTermination()

enter image description here

But when I try to print each bit it gives an error:

for l in lines.iter_lines():
   print l
ssc.start()             # Start the computation
ssc.awaitTermination()

DataStream error

Can someone tell me how can I read each bit from the stream so that I could implement the algorithm on it?

1 Answers1

0

I used the following code:

 streams.foreachRDD(lambda c: function(c))
 function(c):
    c.collect()

This makes an rdd out of each stream and the function collects all the streams