WordCount 需求&准备 ● 图解 ●首先在linux服务器上安装nc工具 nc是netcat的简称,原本是用来设置路由器,我们可以利用它向某个端口发送数据 yum install -y nc ●启动一个服务端并开放9999端口,等一下往这个端口发数据 nc -lk 9999 ●发送数据 话不多说!!!上代码! package cn.itcast.streaming import org.apache.spark.streaming.dstream.{DStream, ReceiverInputDStream} import org.apache.spark.{SparkConf, SparkContext} import org.apache.spark.streaming.{Seconds, StreamingContext} object WordCount { def main(args: Array[String]): Unit = { //1.创建StreamingContext //spark.master should be set as local[n], n > 1 val conf = new SparkConf().setAppName("wc").setMaster("local[*]") val sc = new SparkContext(conf