import org.apache.spark.{SparkContext, SparkConf}
import org.apache.spark.streaming.{Seconds,StreamingContext}
import org.apache.spark.storage.StorageLevel
val conf=new SparkConf().setMaster("local[2]").setAppName("wordcount")
val sc=new SparkContext(conf);
val ssc=new StreamingContext(sc,Seconds(10));
val lines=ssc.socketTextStream("localhost",9999,StorageLevel.MEMORY_AND_DISK_SER);
val wordCount=lines.flatMap(_.split(",")).map(x=>(x,1)).reduceByKey((a,b)=>a+b);
wordCount.print()
ssc.start();
ssc.awaitTermination()