Modules/Sockets/sockClose: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
Line 55: Line 55:
==See Also==
==See Also==
===Functions===
===Functions===
* [http://wiki.mtasa.com/wiki/Modules/Sockets/sockOpen sockOpen()]
{{Modules/Sockets/Functions}}
* [http://wiki.mtasa.com/wiki/Modules/Sockets/sockWrite sockWrite()]
* [http://wiki.mtasa.com/wiki/Modules/Sockets/sockClose sockClose()]


===Events===
===Events===
* [http://wiki.mtasa.com/wiki/Modules/Sockets/onSockOpened onSockOpened]
{{Modules/Sockets/Events}}
* [http://wiki.mtasa.com/wiki/Modules/Sockets/onSockData onSockData]
* [http://wiki.mtasa.com/wiki/Modules/Sockets/onSockClosed onSockClosed]
[[Category:Modules]]

Revision as of 14:31, 25 April 2010


Package-x-generic.png 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 * :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

Functions

Events