As long as the socket server sends data through the same connection, the
existing code is going to work. The socket.getInputStream returns a input
stream which will continuously allow you to pull data sent over the
connection. The bytesToObject function continuously reads data from the
input stream and coverts them to objects. This will continue until the
input stream is closed (i.e., the connection is closed).

TD


On Sun, Apr 20, 2014 at 1:36 AM, YouPeng Yang <yypvsxf19870...@gmail.com>wrote:

> Hi
>   I am studing the structure of the Spark Streaming(my spark version is
> 0.9.0). I have a question about the SocketReceiver.In the onStart function:
>   -------------------------------------------------------
>   protected def onStart() {
>     logInfo("Connecting to " + host + ":" + port)
>     val socket = new Socket(host, port)
>     logInfo("Connected to " + host + ":" + port)
>     blockGenerator.start()
>     val iterator = bytesToObjects(socket.getInputStream())
>     while(iterator.hasNext) {
>       val obj = iterator.next
>       blockGenerator += obj
>     }
>   }
>   ---------------------------------------------------------
>   Here the Socket client is created and read data iteratively. My question
> is the onStart function is only called once by the super class
> NetworkReceiver, and correspondingly read data one time.
>   When the socket server send data again, how does the SocketReceiver read
> the input data,I can find any src hint about the process.
>   In my opinion, the Socket instance should read the data cyclically as
> following:
> -------------------------------------------------------------
> InputStream is = socket.getInputStream()
>
> while(theEndflag){
>    if(is.avariable <= 0){
>      val iterator = bytesToObjects(is)
>      while(iterator.hasNext) {
>       val obj = iterator.next
>       blockGenerator += obj
>      }
>    }
> }
> //theEndflag is the end flag of the loop,shoud be set to false when needed.
>  -----------------------------------------------------------
>
> I know it may not be the right thought,however i am really curious about
> the Socket read process because it hard to understand.
>
> Any suggestions will be appreciated.
>
>
>

Reply via email to