import org.apache.spark.SparkConf

import org.apache.spark.streaming.Seconds

import org.apache.spark.streaming.StreamingContext


object  WordCount extends App {

  val conf=new SparkConf().setMaster("local[2]").setAppName("wordcount")

  val streamContext=new StreamingContext(conf,Seconds(5))

  val lines=streamContext.socketTextStream("myhadoop1", 9999)

                         //监控主机的一个端口  用命令nc -lk 9999

  lines.flatMap {_.split(" ")}.map {(_,1)}.reduceByKey(_+_).print()

  streamContext.start()

  streamContext.awaitTermination()

}