[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: a few questions re LuaSockets
- From: erik@... (Erik Hougaard)
- Date: Tue, 21 Jan 2003 17:22:48 +0100
----- Original Message -----
> >I also recall that Erik Hougaard wrote one for uCore, but I can't find a
> >link to it right now at www.ucore.com.
>
> Found it at http://www.ucore.com/sourcecode.htm .
> --lhf
Hehe.. A couple of pointers with this, in uCore there is a portlister/thread
starter thingie. So when ever a connection is created uCore starts a new
thread and that code is called on the thread. For a while uCore.com was
actually served by that code.
Regarding dynamic content, cgilua is a great place to gain inspiration. The
golden idea (at we have actually recreated in uCore) is to threat HTML as
lua source.
Below is a example from my personal streaming MP3 server that is driven by
uCore (running as a cgi thingie). It shows files and directories and lets
you stream files from the server.
/Erik
<!--$$
-- MP3 Server
BaseDir = "E:\\FTPROOT\\MP3"
BaseDir2 = ServerURL.."mp3" --"http://xxx.xxx.xxx.xxx/mp3"
if Query.PARENT == nil then
ParentDir = "\\"
ParentDir2 = ""
else
if Query.DIR ~= nil then
ParentDir = Query.DIR
ParentDir2 = Query.DIR
else
ParentDir = Query.PARENT
ParentDir2 = Query.PARENT
end
end
if Query.DIR == nil then
MP3Dir = BaseDir .. ParentDir
MP3Dir2 = BaseDir2
else
MP3Dir = BaseDir .. Query.DIR
MP3Dir2 = BaseDir2 .. Query.DIR
end
--if strsub(Query.DIR,-2,-1) == ".." then
--ParentDir = Query.DIR
DirList = getdirs(MP3Dir .. "\\*.*")
FilesList = getfiles(MP3Dir .. "\\*.mp3")
DirNo = 3
DirRows = getn(DirList) / 4
local TestFile = readfrom(MP3Dir.."\\index.jpg")
if TestFile then
IndexJpgExists = 1
closefile(TestFile)
end
$$-->
<html>
<head>
<title>MP3 Server</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="/websupport/mp3web.css" type="text/css">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<center>
<table width="780" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="20" rowspan="6"><img
src="/websupport/marginspace.gif"></td>
<td height="20"><img src="/websupport/marginspace.gif"></td>
<td width="20" rowspan="6"><img
src="/websupport/marginspace.gif"></td>
</tr>
<tr>
<td valign="top" height="59" width="740">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td valign="top" height="59" rowspan="2"><a
href="/cgi-bin/ucorerun.exe/MAIN"><img src="/websupport/mp3web_Logo.jpg"
width="265" height="59" border="0"></a></td>
<td class=txt align="right" valign="top">
<p><b>Welcome $|CGIShow(UserDB,"NAME")|$ to MP3 Server</b></p>
<p align="right"><b><a href="/cgi-bin/ucorerun.exe/TREE">Tree
View</a></b></p>
</td>
</tr>
</table>
</td>
</tr>
<!--$$ IF test='Query.DIR ~= nil' $$-->
<tr>
<td class=txt height="25"><a href="#" OnClick="window.history.go(-1)">Up
to Parent Level</a></td>
</tr>
<!--$$ ENDIF $$-->
<!--$$ IF test='getn(DirList)>2' $$-->
<tr>
<td height="20" valign="top">
<div class="txt" align="left">MP3 Directories<img
src="/websupport/marginspace.gif">
<table width="100%" border="1" cellpadding="2"
bordercolor="#FFFFFF">
<!--$$ LOOP start='I=1', test='I <= DirRows', action='I=I+1'
$$-->
<tr>
<!--$$ LOOP start='D=1',test='D<4',action='D=D+1' $$-->
<!--$$ IF test='DirList[DirNo] ~= nil' $$-->
<td class=pkt height="20" width="12" bgcolor="#FFFFFF"><a
href="/cgi-bin/ucorerun.exe/PLAYDIR?DIR=$|ParentDir2.."\\"..DirList[DirNo]|$
"><img src="/websupport/node.jpg" width="10" height="13"
border="0"></a></td>
<td class=pkthead height="20" bgcolor="#EEEEEE"><a
href="/cgi-bin/ucorerun.exe/MAIN?DIR=$|ParentDir2.."\\"..DirList[DirNo]|$&PA
RENT=$|ParentDir|$">$|DirList[DirNo]|$</a></td>
<!--$$ ENDIF $$-->
<!--$$ DirNo = DirNo + 1 $$-->
<!--$$ ENDLOOP $$-->
</tr>
<!--$$ ENDLOOP $$-->
</table>
</div>
<div align="center"></div>
</td>
</tr>
<!--$$ ENDIF $$-->
<!--$$ IF test='IndexJpgExists' $$-->
<tr>
<td><img width="100" height="100"
src="$|MP3Dir2.."/index.jpg"|$"></td>
</tr>
<!--$$ ENDIF $$-->
<!--$$ IF test='getn(FilesList) > 0' $$-->
<tr>
<td valign="top" height="73">
<div class="txt" align="left"><a
href="/cgi-bin/ucorerun.exe/PLAYDIR?DIR=$|ParentDir|$">
</a>
<table width="100%" border="1" cellpadding="2" bgcolor="#FFFFFF"
bordercolor="#FFFFFF">
<tr>
<td class=txt><a
href="/cgi-bin/ucorerun.exe/PLAYDIR?DIR=$|ParentDir|$">Play all MP3 files in
this directory</a></td>
</tr>
</table>
<table width="100%" border="1" bordercolor="#FFFFFF">
<!--$$ LOOP start='I=1', test='FilesList[I + 1] ~= nil',
action='I=I+1' $$-->
<tr>
<!--$$
MP3Info = getmp3info(MP3Dir.."\\"..FilesList[I])
if MP3Info == nil then
MP3Info = {Artist="",Album="",Title=FilesList[I]}
else
if MP3Info.Title == nil or
MP3Info.Title == "" or
MP3Info.Title == " " then
MP3Info.Title = FilesList[I]
end
end
$$-->
<td class=pkt height="25" width="13" bgcolor="#FFFFFF">
<a
href="/cgi-bin/ucorerun.exe/PLAY?DIR=$|ParentDir|$&FILE=$|FilesList[I]|$"><i
mg src="/websupport/node.jpg" width="10" height="13" border="0"></a></td>
<td class=pkt bgcolor="#DDDDDD">$|MP3Info.Artist or ''|$</td>
<td class=pkt bgcolor="#DDDDDD">$|MP3Info.Album or ''|$</td>
<td class=pkt bgcolor="#DDDDDD"><a
href="/cgi-bin/ucorerun.exe/PLAY?DIR=$|ParentDir|$&FILE=$|FilesList[I]|$">$|
MP3Info.Title or ''|$</a></td>
<td class=pkt width="30" bgcolor="#DDDDDD">$|MP3Info.Bitrate or
0|$kbps</td>
<td class=pkt width="15" bgcolor="#DDDDDD"><a href="$|MP3Dir2
.."/"..FilesList[I]|$">DL</a></td>
</tr>
<!--$$ ENDLOOP $$-->
</table>
</div>
</td>
</tr>
<!--$$ENDIF $$-->
<tr>
<td align="center" class=txt height="25"><b>© Copyright Erik
Hougaard 2002</b></td>
</tr>
</table>
</center>
</body>
</html>