Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
ioan
Level 7

Socket.ReceiveStr(1000) reads to the first EOL only?

aline = Socket.ReceiveStr(1000)

Does this code reads the string to the first EOL or reads 1000 characters?
https://github.com/e1ioan/
http://rokucam.com
0 Kudos
4 Replies
EnTerr
Level 8

Re: Socket.ReceiveStr(1000) reads to the first EOL only?

It will just read (up to) 1000 bytes, I doubt there is any consideration of EOL there,. I am inclined to think of receiveStr() as just a shortcut for doing socket.receive() to a roByteArray and then returning .toAsciiString() off that
0 Kudos
ioan
Level 7

Re: Socket.ReceiveStr(1000) reads to the first EOL only?

"EnTerr" wrote:
It will just read (up to) 1000 bytes, I doubt there is any consideration of EOL there,. I am inclined to think of receiveStr() as just a shortcut for doing socket.receive() to a roByteArray and then returning .toAsciiString() off that

So I guess to read to EOL, I'll have to read byte by byte until EOL. It would have been nice if ReadLn was implemented
https://github.com/e1ioan/
http://rokucam.com
0 Kudos
Roku Employee
Roku Employee

Re: Socket.ReceiveStr(1000) reads to the first EOL only?

"ioan" wrote:
"EnTerr" wrote:
It will just read (up to) 1000 bytes, I doubt there is any consideration of EOL there,. I am inclined to think of receiveStr() as just a shortcut for doing socket.receive() to a roByteArray and then returning .toAsciiString() off that

So I guess to read to EOL, I'll have to read byte by byte until EOL. It would have been nice if ReadLn was implemented

You could implement that yourself, either as part of your socket protocol if you control it, or by implementing a simple stream/buffering layer on top of socket Receive.
0 Kudos
ioan
Level 7

Re: Socket.ReceiveStr(1000) reads to the first EOL only?

Another question, if I have in a function a while loop reading one byte at the time, trying to find Chr(10), do I have to do a wait for a "roSocketEvent" inside the function even if I have a "roSocketEvent" inside the main loop?

function main() as void
  '...
  while true
        event = wait(0, port)
        if type(event) = "roSocketEvent" then
           doSomething()
        end if
  end while
end function


function doSomething() as string
   while true
        event = wait(0, port) ' <-- is this necessary?
        if type(event) = "roSocketEvent" then ' <-- is this necessary?
           ' read from the socket 1000 bytes 1 by 1
        end if
   end while
end function
https://github.com/e1ioan/
http://rokucam.com
0 Kudos