http server with corona

Hi there :slight_smile:

is there a demo for a http server around I could implement in my app?

The idea is to use the server for backups on iOS.

The app should give an IP where it can be reached, the user points
his Browser to this IP (for sure he have to be in the same Wifi Network)
gets a HTML page where he can download data (backup) or Upload the same.

Any Source is welcomed :slight_smile:

cheers
chris
[import]uid: 4795 topic_id: 15964 reply_id: 315964[/import]

found that
http://code.google.com/p/lua-web-server/

just don’t know right now how to implement :slight_smile:

greets
chris
[import]uid: 4795 topic_id: 15964 reply_id: 59125[/import]

i am already at the point where i can send my backups…
now stuck where i receive them to my lua server (right now i test upload a gif file)

i get a POST header so i know the file is in send mode (File Upload)

i get a lot of headers (see bellow)
problem is that

 if request:sub(1,4) == "POST" then  
 print ("GET DATA UPLOAD")  
 request,err = client:receive()  
  
 while not err do  
 client:settimeout(5110)  
 print ("before receive")  
 request,err = client:receive()  
 print ("after receive")  
 print (request)  
 if request == nil then print ("request ist NIL") end  
 --client:close()   
 end  
 print ("done")  
 end  

request,err = client:receive() does not come back from a request even I made client:settimeout(10)

and I don’t know how to know exactly the start and end from the file.

Isn’t there a simple solution? :slight_smile:

here the data i get
chris

User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_1) AppleWebKit/534.48.3 (KHTML, like Gecko) Version/5.1 Safari/534.48.3
Content-Length: 5239
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Origin: http://192.168.1.11:8080
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryFKdZzEnF6dDjXcs9
Referer: http://192.168.1.11:8080/
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: keep-alive

------WebKitFormBoundaryFKdZzEnF6dDjXcs9
Content-Disposition: form-data; name=“file”; filename=“lua-2.gif”
Content-Type: image/gif

HTTP/1.1 200/OK
Server: Ladle
Content-Type:image/gif

GIF87a?
??r?#??? 9B? !F??q?P?0h@?>???$2?AJG?“Kt’P"p4?
P?!UU?D?$[q???DF,?uZ??#?4???x?~8_
?H?t???I???]??@Z^- ?~D???
h#v?VQ??w?f???$?W ??1?&u??u?s”?B;?T?\
A24b?0??"/?};d]3??r??w?;
Al?%?2???{???0??X+?V
??IB???fQ{???#???d?{Vo"X?y PP??:?0e?)?zq?272???5?
!K?I?n??AsCPP?L?jP?ZwG?@??q? ??j?H3wP?;N??9?5?B??`J?C?z+"??A??9?#

??n?U?0*??"q?H??L??N??
------WebKitFormBoundaryFKdZzEnF6dDjXcs9
Content-Disposition: form-data; name=“submit.x”

[import]uid: 4795 topic_id: 15964 reply_id: 59189[/import]

hey guruk,
did you happen to figure this out ? I have been looking for solution for quite a while.
thanks :slight_smile:
n [import]uid: 80100 topic_id: 15964 reply_id: 77539[/import]

hi, don’t have so much time… bellow some code excerpt from my app (i can’t tell you in details more about, just have a look and try around)

what i remember and that was important is the order where you set the timeout
tcpServer:settimeout( 0 )
client = tcpServer:accept()

------ see bellow

– DecodeCommunication
local function decodeCommunication( str )
local t = {}
local function helper( line ) table.insert( t , line ) return “” end
helper( ( str:gsub( “(.-)*” , helper ) ) )
return t

end

local function createTCPServer( ip, port )

– Create Socket
local tcpServerSocket , err = socket.tcp()
local backlog = 0

– Check Socket
if tcpServerSocket == nil then
return nil , err
end

– Allow Address Reuse
tcpServerSocket:setoption( “reuseaddr” , true )

– Bind Socket
local res, err = tcpServerSocket:bind( ip , port )
if res == nil then
return nil , err
end

– Check Connection
res , err = tcpServerSocket:listen( backlog )
if res == nil then
return nil , err
end

– Return Server
return tcpServerSocket

end

—>>> Game Loop (Clouds and PadServer)
local gameLoop = function()

if (firststart == 1) then

print (“setup server”)
– getyp my local IP
client = socket.connect( “www.google.com”, 80 )
ip, port = client:getsockname()
print ("Connect me at: " … ip)
client:close()

–start server
tcpServer = createTCPServer (ip,8080)
print (tcpServer)

ip, port = tcpServer:getsockname()

firststart =0
end

tcpServer:settimeout( 0 )
client = tcpServer:accept()

if (client ~= nil) then
ip, port = client:getpeername()
–print("Got connection from "… ip … " on port " … port)

local line, err = client:receive()
if not err then
[import]uid: 4795 topic_id: 15964 reply_id: 77563[/import]

Awesome, Guruk, many thanks for such a quick reply! Will try it out.
Happy New Year ! :slight_smile: [import]uid: 80100 topic_id: 15964 reply_id: 77572[/import]