Re: mini WEB-Server (alt mini FTP)
Verfasst: Do 30. Aug 2012, 15:01
Sorry,
war wol gestern doch schon zu spät habe da ":" mit "|" verwechselt.
war wol gestern doch schon zu spät habe da ":" mit "|" verwechselt.

Retro Style Eigenbau Computer mit Parallax Propeller
https://www.hive-project.de/board/
Code: Alles auswählen
PUB main
sock.start(1, 2, 3, 4, -1, 7, @mac_addr, @ip_addr)
rr.start
webserver
Code: Alles auswählen
PRI webserver | sockidx
' Setup listening sockets
\sock.listen(80, @tcp_webrx1, rxlen, @tcp_webtx1, txlen)
repeat
if \sock.isConnected ' is a client connected?
if \_webThread == 0 ' process the client connection, check for success
\sdfat.unmountPartition
repeat while \sock.txflush ' flush txbuffer
\sock.close ' close socket
\sock.relisten ' force socket to listen again, using the previous settings
Code: Alles auswählen
...
a:= sdfat.fileSize
b:= a / 512 'Blöcke von 512Byte ermitteln
a:= a - (b * 512) 'restgröße
repeat i from 0 to b
sdfat.readData(@SDP, 512)
repeat while \sock.txflush ' flush txbuffer
sock.txdata(@SDP,512)
sdfat.readData(@SDP, 512)
repeat while \sock.txflush ' flush txbuffer
sock.txdata(@SDP,a)
return 0
Code: Alles auswählen
repeat i from 0 to b
Code: Alles auswählen
repeat b
Code: Alles auswählen
' long webstack[64] ' stack for webserver cog
long webstack[256] ' stack for webserver cog
Code: Alles auswählen
' stack long 0[128] ' stack for new cog (currently ~74 longs, using 128 for expansion)
stack long 0[256] ' stack for new cog (currently ~74 longs, using 128 for expansion)
Code: Alles auswählen
a:= sdfat.fileSize
b:= a / 512 'Blöcke von 512Byte ermitteln
a:= a - (b * 512) 'restgröße
ser.writeString(string("Ready", $0D))
repeat b
sdfat.readData(@SDP, 512)
sock.txdata(@SDP,512)
if a>0
sdfat.readData(@SDP, a)
sock.txdata(@SDP,a)
return 0
Code: Alles auswählen
repeat
h:=sdfat.readData(@sendwebBuffer,BufferSize) ' now we are reading the first BufferSize (1024 byte)
if h=<0 ' if there are no bytes to read, then exit the loop
quit
else
web.txdata(@sendwebBuffer,h) ' send the h bytes read (max 1024 byte)
return 0