Modules/Sockets/onSockClosed

From Multi Theft Auto: Wiki
Revision as of 13:53, 25 April 2010 by MCvarial (talk | contribs) (Created page with '__NOTOC__ {{ModuleFunction|Sockets}} This event is triggered when a socket was destroyed. ===Parameters=== * '''socket''' userdata representing a socket. ===Source=== The sourc…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


Package-x-generic.png This function is provided by the external module Sockets. You must install this module to use this function.

This event is triggered when a socket was destroyed.

Parameters

  • socket userdata representing a socket.

Source

The source of this event is getRootElement()

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",80)

addEventHandler("onSockOpened",root,
   function (socket)
      if socket == ircSocket then
         sockWrite(socket,"USER mta mta * MCvarial & Gamesnert")
         sockWrite(socket,"NICK mta")
         sockWrite(socket,"JOIN #mta")

         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

See also