Lua
Lua
Move a Connection into a Socket Set
See more Socket/SSL/TLS Examples
Demonstrates Socket.TakeSocket, which moves a connection into a newly created member of this object's socket set. After one or more calls, the object acts as a set of sockets.
Background. A socket set groups multiple connections so they can be monitored together with the SelectForReading and SelectForWriting methods. After success, the source socket holds no connection.
Chilkat Lua Downloads
local chilkat = require("chilkat")
local listenSock = chilkat.Socket.new()
local success = listenSock:bind_and_listen(5000, 25)
if not success then
print(listenSock.last_error_text)
return
end
local connectedSock = chilkat.Socket.new()
success = listenSock:accept_next(20000, connectedSock)
if not success then
print(listenSock.last_error_text)
return
end
-- Move the connection out of connectedSock and into a newly created member of this object's socket
-- set. After one or more such calls, socketSet acts as a set of connected sockets (useful with the
-- SelectForReading / SelectForWriting methods). After success, connectedSock holds no connection.
local socketSet = chilkat.Socket.new()
success = socketSet:take_socket(connectedSock)
if not success then
print(socketSet.last_error_text)
return
end
print("Connection added to the socket set.")