Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Level 8

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
Highlighted
Level 10

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
Highlighted
Level 8

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
Highlighted
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
Highlighted
Level 8

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