【发布时间】:2013-02-15 09:45:05
【问题描述】:
代码
function radiotest(host,port)
local rstr="Online"
local sock, err = socket.tcp()
if not sock then
return "Failed"
end
sock:settimeout(1)
local res, err = sock:connect(host, port)
if not res then
return "offline"
else
sock:settimeout(1)
sock:send("GET /index.html HTTP/1.0\r\n UserAgent: SHOUTcast Song Status \r\n Accept: */*\r\n\r\n")
sock:settimeout(3)
local data=sock:receive('*a')
sock:close()
print(data)
-- Further processing content here
end
end
print( radiotest( "10.*.*.*", 1234 ) )
上面的socket连接返回我:
ICY 404 Resource Not Found
icy-notice1:<BR>SHOUTcast Distributed Network Audio Server/win32 v1.9.7<BR>
icy-notice2:The resource requested was not found<BR>
我认为问题出在我的标题列表中,但我无法追踪它。
页面在所有浏览器中都可以正常打开(Opera 确实需要被屏蔽为另一个浏览器;否则它只会继续下载所有歌曲)。
我尝试在 sock:send() 中使用以下字符串
GET /index.html HTTP/1.0\r\n UserAgent: SHOUTcast Song Status (Mozilla Compatible)\r\n\r\nGET /index.html HTTP/1.0\r\n UserAgent: Opera/9.80 (Windows NT 6.1; Win64; x64) Presto/2.12.388 Version/12.12\r\n\r\nGET /index.html HTTP/1.0\r\n UserAgent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17\r\n\r\n
我完全被这部分困住了。如何使用socket.tcp() 获取页面?
【问题讨论】:
-
任何不使用 luasocket 的 http 子模块而不是原始 tcp 的理由。 w3.impa.br/~diego/software/luasocket/http.html
-
@JaneT 我也会将它与游戏服务器合并,使用我已有的 DLL。
-
你能发布一个数据包捕获吗?
-
@Brad 如果通过数据包捕获,您指的是我收到的数据,那么我已经将它放在问题中。
ICY 404 Resource Not Found这是我得到的。如果不是你的意思,请告诉我如何获取数据包跟踪。 -
@BackinaFlash,我看到你发布的内容,但我更愿意查看原始数据包捕获,看看是否有任何奇怪的事情发生。您可以使用 Wireshark 进行捕获。 wireshark.org
标签: sockets lua shoutcast luasocket