मैं लुआ प्रोग्रामिंग भाषा का उपयोग कर एक सर्वर लिख रहा हूं, और नेटवर्क परत LuaSocket पर आधारित है।लुसकेट लाइब्रेरी में सॉकेट को कैसे बंद किया गया है या नहीं?
और मुझे किसी सॉकेट को बंद करने के लिए कोई तरीका नहीं मिला है या इसके संदर्भ मैनुअल में नहीं है, इसके अलावा केवल डेटा पढ़ने की कोशिश करें (यह कॉल करते समय शून्य और स्ट्रिंग 'क्लोज' लौटाएगा)।
मेरे कोड इस तरह दिखता है:
local socket = require 'socket'
local server = socket.tcp()
local port = 9527
server:bind('*', port)
local status, errorMessage = server:listen()
if status == 1 then
printf('Server is launched successfully on port %u', port)
else
printf('Server listen failed, error message is %s', errorMessage)
return
end
local sockets = {server}
while true do
local results = socket.select(sockets)
for _, sock in ipairs(results) do
if sock == server then
local s = server:accept()
callback('Connected', s)
table.insert(sockets, s)
printf('%s connected', s:getsockname())
else
-- trying to detect socket is closed
if sock:isClosed() then
callback('Disconnected', sock)
for i, s in ipairs(sockets) do
if s == sock then
table.remove(sockets, i)
break
end
end
printf('%s disconnected', sock:getsockname())
else
callback('ReadyRead', sock)
end
end
end
end
'सत्य' लूप के अंदर 'सर्वर: settimeout' कॉल करें। – hjpotter92