Modules/Sockets/sockClose: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 23: | Line 23: | ||
function (socket) | function (socket) | ||
if socket == ircSocket then | if socket == ircSocket then | ||
sockWrite(socket,"USER mta mta * : | sockWrite(socket,"USER mta mta * :Bot\r\n") | ||
sockWrite(socket,"NICK mta") | sockWrite(socket,"NICK mta\r\n") | ||
sockWrite(socket,"JOIN #mta") | sockWrite(socket,"JOIN #mta\r\n") | ||
outputServerLog("IRC: Connected!") | outputServerLog("IRC: Connected!") | ||
Latest revision as of 17:16, 7 May 2010
| This function is provided by the external module Sockets. You must install this module to use this function. | |
This function destroys a socket.
Syntax
bool sockClose ( socket theSocket )
Required arguments
- theSocket: The socket to close
Returns
Returns a boolean true if the socket was closed, false otherwise.
Example
This piece of code connects to irc.gtanet.com, joins #mta and quits in 10 seconds.
local root = getRootElement()
local ircSocket = sockOpen("irc.gtanet.com",6667)
addEventHandler("onSockOpened",root,
function (socket)
if socket == ircSocket then
sockWrite(socket,"USER mta mta * :Bot\r\n")
sockWrite(socket,"NICK mta\r\n")
sockWrite(socket,"JOIN #mta\r\n")
outputServerLog("IRC: Connected!")
setTimer(disconnect,10000,1)
end
end
)
addEventHandler("onSockData",root,
function (socket,data)
if socket == ircSocket then
outputServerLog(data)
end
end
)
addEventHandler("onSockClosed",root,
function (socket)
if socket == ircSocket then
outputServerLog("IRC: disconnected!")
end
end
)
function disconnect ()
sockClose(ircSocket)
end