Last updated
nc -lk 29999test test again here I am
test test test again again//following is the scala code:
package com.jentekco.spark
import org.apache.spark._
import org.apache.spark.streaming._
//import org.apache.spark.streaming
// .StreamingContext._
import org.apache.log4j._
object streaming1 {
def main(args: Array[String]): Unit = {
Logger.getLogger("org").setLevel(Level.ERROR)
// Create a local StreamingContext
// with two working thread and batch interval
// of 1 second.
// The master requires 2 cores to prevent a
// starvation scenario.
val conf = new SparkConf().setMaster("local[2]")
.setAppName("NetworkWordCount")
val ssc = new StreamingContext(conf, Seconds(1))
// Create a DStream that will connect to
// hostname:port, like localhost:9999
val lines = ssc.socketTextStream("10.0.0.46", 29999)
// Split each line into words
val words = lines.flatMap(_.split(" "))
//import org.apache.spark.streaming
// .StreamingContext._
// Count each word in each batch
val pairs = words.map(word => (word, 1))
val wordCounts = pairs.reduceByKey((a,b)=>a+b)
// Print the first ten elements of each
// RDD generated in this DStream to the console
wordCounts.print()
ssc.start() // Start the computation
ssc.awaitTermination()
// Wait for the computation to terminate
} }import findspark
findspark.init()
import pyspark
from pyspark import SparkConf,SparkContext
from pyspark.streaming import StreamingContext
from pyspark.sql import Row,SQLContext
import sys
import requests
#Create a local StreamingContext with two working thread and batch interval of 1 second
sc = SparkContext("local[2]", "NetworkWordCount")
ssc = StreamingContext(sc, 1)
#Create a DStream that will connect to hostname:port, like localhost:9999
lines = ssc.socketTextStream("10.0.0.46", 29999)
words = lines.flatMap(lambda _:_.split(" "))
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() # Start the computation
ssc.awaitTermination() # Wait for the computation to terminate