Advertisement
Stiepen

Untitled

Jan 21st, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. Hey, some small corrections:
  2. [quote name='Aichan' timestamp='1358812827' post='78548']
  3. /!\ You are limited (by default) to 12 sockets per webinterface
  4. [/quote]
  5. Actually its only 10 by default
  6. [quote name='Aichan' timestamp='1358812827' post='78548']
  7. socket.subscribeEvent(String handle, String event)
  8. - Don't know what it is (Will edit when I know)
  9. [/quote]
  10. it actually enables you to receive events, i highly recommend to do [code]socket.subscribeEvent(handle, "text")[code] for every new connection unless you only want to send data.
  11. [quote name='Aichan' timestamp='1358812827' post='78548']
  12. socket.connect(String handle, String ip, int port, bool SSL)
  13. - Connects to a listening socket (So basically you are the client and you connect to a server).
  14. - The handle is the same as the one you registered using registerHandle(String handle)
  15. - The ip is the destination socket's adress (I.E : 173.194.78.94 (One of Google's servers))
  16. - The port is the destination socket's listening port (If we want to connect to the webserver we'd say "80")
  17. - The SSL bool isn't doing anything at the moment you can give him FALSE
  18. [CODE][size=4]socket.[/size]connect("MySocket", "173.194.78.94", "80", "false")[/CODE]
  19. [/quote]
  20. [code]socket.connect("MySocket", "173.194.78.94", 80, false)[/code] works now too.
  21. [quote name='Aichan' timestamp='1358812827' post='78548']
  22.  
  23. socket.writeLine(String Handle, String content)
  24. - Sends "content" through the socket identified by "Handle"
  25. [CODE]socket.writeLine("MySocket", "Hey, socket is working !")[/CODE]
  26.  
  27. Note 1 : : All the methods return values depending on errors
  28. [CODE]
  29. ERR_CONNECTED = -1 Already connected
  30. ERR_NOT_CONNECTED = -2 No Connection etablished
  31. ERR_INVALID_HANDLE = -3 Handle not registered
  32. ERR_WRONG_OWNER = -4 Currently unused
  33. ERR_UNKNOWN_HOST = -5 Can't connect because host not avaible
  34. ERR_CANT_CONNECT = -6 Other connection error
  35. ERR_UNKNOWN = -7 Unknown error occured
  36. ERR_INSUFFICANT_ARGS = -8 Wrong param number passed
  37. [/CODE]
  38. [/quote]
  39. Every function now returns this number as first and a describing String as second number.
  40. [quote name='Aichan' timestamp='1358812827' post='78548']
  41.  
  42. Note 2 : All the args have to be string (Even for "int port" and "bool SSL") It is a known issue and will be fixed
  43. [/quote]
  44. This piece of information is outdated. It still support string arguments for backwards compatibility but integers and booleans now work too
  45. [quote name='Aichan' timestamp='1358812827' post='78548']
  46.  
  47. How do we read what is sent through the socket? What method?
  48.  
  49. To read a socket, we do something a little bit different, we listen to triggered events.
  50. Different events are pulled by the peripheral here is a list I'll complete when I'll know them all :
  51. [CODE]
  52. "socket_line_received" Tells you a line has been received through the socket
  53. [/CODE]
  54. [/quote]
  55. In order to get This event you need to subscribe to the text event first. See above
  56. [quote name='Aichan' timestamp='1358812827' post='78548']
  57. [CODE]
  58. "socket_remote_closed" Tells you the socket has been remotely closed
  59. [/CODE]
  60.  
  61. And here's a little example on how to read :
  62. [CODE]
  63.  
  64. -- Waits for a line to be received
  65. local function readLine()
  66. while true do
  67. e, p1, p2 = os.pullEvent()
  68. if e == "socket_line_received" then
  69. return p2
  70. elseif e == "socket_remote_closed" then
  71. return nil
  72. end
  73. end
  74. end
  75. [/CODE]
  76. [/quote]
  77. Also it appears you copied quite a lot from my wiki :P - well its not updated yet so use this thread as reference :P
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement