Template:Modules/Sockets/Functions: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
This function | This function creates a socket. | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
userdata sockOpen ( string host, int port ) | |||
</syntaxhighlight> | |||
</syntaxhighlight> | |||
===Required Arguments=== | ===Required Arguments=== | ||
*'''host:''' This is a host name | *'''host:''' This is a host name e.g. "www.google.com" | ||
*'''Port:''' This is the port on which to connect e.g. 80 | |||
*''' | |||
===Returns=== | ===Returns=== | ||
Returns ' | Returns 'userdata' if the correct arguments were given ''false'' otherwise. | ||
==Example== | ==Example== | ||
This example shows you how you can | This example shows you how you can connect to irc. | ||
'''PHP:''' (for the page that LUA expects to be at ''<nowiki>http://www.example.com/page.php</nowiki>'') | '''PHP:''' (for the page that LUA expects to be at ''<nowiki>http://www.example.com/page.php</nowiki>'') | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
local socket = sockOpen("irc.gtanet.com",80) | |||
addEventHandler("onSockOpened",getRootElement(), | |||
function (sock) | |||
if sock == socket then | |||
sockWrite(socket,"USER IRCbot botname * :Gamesnert & MCvarial") | |||
sockWrite(socket,"NICK botname") | |||
end | |||
end | |||
end | ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
'''Important Note''': ''Sockets are asynchronous this means if sockOpen() return true it doesn't mean it's already created!'' | |||
'''Important Note''': '' | |||
==See Also== | ==See Also== |
Revision as of 13:12, 25 April 2010
This function creates a socket.
Syntax
userdata sockOpen ( string host, int port )
Required Arguments
- host: This is a host name e.g. "www.google.com"
- Port: This is the port on which to connect e.g. 80
Returns
Returns 'userdata' if the correct arguments were given false otherwise.
Example
This example shows you how you can connect to irc.
PHP: (for the page that LUA expects to be at http://www.example.com/page.php)
local socket = sockOpen("irc.gtanet.com",80) addEventHandler("onSockOpened",getRootElement(), function (sock) if sock == socket then sockWrite(socket,"USER IRCbot botname * :Gamesnert & MCvarial") sockWrite(socket,"NICK botname") end end )
Important Note: Sockets are asynchronous this means if sockOpen() return true it doesn't mean it's already created!