Modules/Sockets/sockWrite: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Added Polish reference)
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<pageclass class="#AA7592" subcaption="Sockets Module"></pageclass>
__NOTOC__
__NOTOC__
{{ModuleFunction|Sockets}}
{{ModuleFunction|Sockets}}
Line 23: Line 24:
   function (socket)
   function (socket)
       if socket == ircSocket then
       if socket == ircSocket then
         sockWrite(socket,"USER mta mta * MCvarial & Gamesnert")
         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!")
Line 54: Line 55:
</syntaxhighlight>
</syntaxhighlight>


==See also==
==See Also==
===Functions===
{{Modules/Sockets/Functions}}
{{Modules/Sockets/Functions}}
===Events===
{{Modules/Sockets/Events}}
[[pl:Modules/Sockets/sockWrite]]

Latest revision as of 22:26, 15 January 2022


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

This function writes data to a socket.

Syntax

bool sockWrite ( socket theSocket, string data)

Required arguments

  • theSocket: The socket to write the data to.
  • data: The data you wanna send.

Returns

Returns a boolean true if the data was send, 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

See Also

Functions

Events