Modules/Sockets/onSockData: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 4: | Line 4: | ||
===Parameters=== | ===Parameters=== | ||
* '''socket''' userdata representing a socket. | <syntaxhighlight lang="lua"> | ||
* '''data''' a string with the data that was received. | userdata socket, string data | ||
</syntaxhighlight> | |||
* '''socket''': userdata representing a socket. | |||
* '''data''': a string with the data that was received. | |||
===Source=== | ===Source=== | ||
The source of this event is | The [[event system#Event source|source]] of this event is the [[root element]]. | ||
==Example== | ==Example== | ||
Line 52: | Line 56: | ||
==See Also== | ==See Also== | ||
===Functions=== | ===Functions=== | ||
{{Modules/Sockets/Functions}} | |||
===Events=== | ===Events=== | ||
{{Modules/Sockets/Events}} | |||
Revision as of 14:24, 25 April 2010
This function is provided by the external module Sockets. You must install this module to use this function. | |
This event is triggered when data is received on a socket.
Parameters
userdata socket, string data
- socket: userdata representing a socket.
- data: a string with the data that was received.
Source
The source of this event is the root element.
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