与Rebol/Core
(278-3-1)一起玩弄一种类似的网络服务器来提供一个静态文本,包含一个重定向链接到一个新的服务位置,显然是一个不可捕捉的错误。调试并避免定期REBOL2错误,try []不会(?)捕获?
错误的具体位置似乎在2006年由Carl Sassenrath
自己编写的示例代码中,所以我有点困惑,在这些年后可能会有一个未被发现的错误。
我有三个脚本同时运行,监视三个单独的端口。从本质上讲,脚本的工作原理应该是......当多个浏览器一次(在所有并行脚本中)重复访问时,它看起来似乎相当稳定......但一个接一个地失败。有时候2分钟,有时20分钟后后 - 甚至是60分钟后加入打印语句有时后 - 但他们最终会失败这样的:
** Script Error: Out of range or past end
** Where: forever
** Near: not empty? request: first http-port
我已经试过包装程序循环的几乎每一个部分尝试[] [例外],但错误仍然发生。不幸的是我的搜索功能似乎每年的这个时候都很弱,因为我还没有找到任何可以解释问题的东西。
的代码是卡尔·萨森拉斯的Tiny Web Server一个削减版本,稍加修改绑定到特定的IP,并发出HTML而不是加载文件:
REBOL [title: "TestMovedServer"]
AppName: "Test"
NewSite: "http://test.myserver.org"
listen-port: open/lines tcp://:81 browse http://10.100.44.6?
buffer: make string! 1024 ; will auto-expand if needed
forever [
http-port: first wait listen-port
clear buffer
while [not empty? request: first http-port][
print request
repend buffer [request newline]
print "----------"
]
repend buffer ["Address: " http-port/host newline]
print buffer
Location: ""
mime: "text/html"
parse buffer ["get" ["http" | "/ " | copy Location to " "]]
data: rejoin [{
<HTML><HEAD><TITLE>Site Relocated</TITLE></HEAD>
<BODY><CENTER><BR><BR><BR><BR><BR><BR>
<H1>} AppName { have moved to <A HREF="} NewSite {">} NewSite {</A></H1>
<BR><BR><BR>Please update the link you came from.
<BR><BR><BR><BR><BR><A HREF="} NewSite Location {">(Continue directly to the requested page)</A>
</CENTER></BODY></HTML>
}]
insert data rejoin ["HTTP/1.0 200 OK^/Content-type: " mime "^/^/"]
write-io http-port data length? data
close http-port
print "============"
]
我很期待看到你伙计们就是这样做的!
谢谢sqlab。 – fsteff
小心解释您是如何得出原始代码是从关闭连接读取的结论?调试步骤将不胜感激。 – fsteff
结论来自考虑和试验的结合以及大量的经验 – sqlab