# from pyspark import SparkContext
# myrange = SparkContext.range(0,1000).toDF("number")
# print (myrange)

from pyspark import SQLContext
from pyspark import SparkContext
#from pyspark import SparkSession
# sc = SparkContext()
# myrange = sc.range(1000).toDF("number")
# print (myrange)

from pyspark import SparkContext
from pyspark.streaming import StreamingContext

# Create a local StreamingContext with two working thread and batch interval of 1 second
sc = SparkContext("local[2]","NetworkCount")
ssc = StreamingContext(sc,1)

# Create a DStream that will connect to hostname:port, like localhost:9999
lines = ssc.socketTextStream("localhost",9999)

# Split each line into words
words = lines.flatMap(lambda line: line.split(" "))

# Count each word in each batch
pairs = words.map(lambda word: (word,1))
wordCounts = pairs.reduceByKey(lambda x,y : x+ y)

# Print the first ten elements of each RDD generated in this DStream to the console
wordCounts.pprint()
ssc.start()
ssc.awaitTermination()