aline = Socket.ReceiveStr(1000)
Does this code reads the string to the first EOL or reads 1000 characters?
aline = Socket.ReceiveStr(1000)
Does this code reads the string to the first EOL or reads 1000 characters?
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
“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
“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.
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