Hi all!
I'm tring to request a page from a server. I've slready studied the WLAN example, but i noticed that the recive operation is inside a loop.
When I tried to obtain tha data of a page, I understand that a single recv is not enougth for all data.
How can I make a loop that ends whal all data are obtained?
Thanks
WLAN data
Moderators: Shine, Insert_witty_name
Do you mean something like this?
while (Socket:IsConnected(MySock))
MySock.recv(data)
end
Because I aòready know about this function but I think that this function return true when I can use the recv o send command.
Instead I need to know if there are some data pending on the connection, data thai i don't have already recived.
while (Socket:IsConnected(MySock))
MySock.recv(data)
end
Because I aòready know about this function but I think that this function return true when I can use the recv o send command.
Instead I need to know if there are some data pending on the connection, data thai i don't have already recived.
Well obviously the simplelest way is to do socket:isconnected() to get data.. and to setup a end loop code.
while (variable) do
if (not socket:isconnected()) then
variable = nil
.. or a timer to force it to do a timeout code.
end
do other stuff here
end
Please note with the HTML it is designed to close the connection right after it sends its data. So if the socket isnt connected (You have the rest of the loop to get the data)
while (variable) do
if (not socket:isconnected()) then
variable = nil
.. or a timer to force it to do a timeout code.
end
do other stuff here
end
Please note with the HTML it is designed to close the connection right after it sends its data. So if the socket isnt connected (You have the rest of the loop to get the data)
Code: Select all
recieve = 0
total = ""
while recieve ~= 2 do
buffer = socket:recv()
if string.len(buffer) > 0 then
recieve = 1
total = total..buffer
else
if recieve == 1 then recieve =2 end
end
end
0, nothing has been recieved
1, is recieving
2, has recieved, but is no longer recieving, so break
This is how Ive done it...