Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Hey, some small corrections:
- [quote name='Aichan' timestamp='1358812827' post='78548']
- /!\ You are limited (by default) to 12 sockets per webinterface
- [/quote]
- Actually its only 10 by default
- [quote name='Aichan' timestamp='1358812827' post='78548']
- socket.subscribeEvent(String handle, String event)
- - Don't know what it is (Will edit when I know)
- [/quote]
- 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.
- [quote name='Aichan' timestamp='1358812827' post='78548']
- socket.connect(String handle, String ip, int port, bool SSL)
- - Connects to a listening socket (So basically you are the client and you connect to a server).
- - The handle is the same as the one you registered using registerHandle(String handle)
- - The ip is the destination socket's adress (I.E : 173.194.78.94 (One of Google's servers))
- - The port is the destination socket's listening port (If we want to connect to the webserver we'd say "80")
- - The SSL bool isn't doing anything at the moment you can give him FALSE
- [CODE][size=4]socket.[/size]connect("MySocket", "173.194.78.94", "80", "false")[/CODE]
- [/quote]
- [code]socket.connect("MySocket", "173.194.78.94", 80, false)[/code] works now too.
- [quote name='Aichan' timestamp='1358812827' post='78548']
- socket.writeLine(String Handle, String content)
- - Sends "content" through the socket identified by "Handle"
- [CODE]socket.writeLine("MySocket", "Hey, socket is working !")[/CODE]
- Note 1 : : All the methods return values depending on errors
- [CODE]
- ERR_CONNECTED = -1 Already connected
- ERR_NOT_CONNECTED = -2 No Connection etablished
- ERR_INVALID_HANDLE = -3 Handle not registered
- ERR_WRONG_OWNER = -4 Currently unused
- ERR_UNKNOWN_HOST = -5 Can't connect because host not avaible
- ERR_CANT_CONNECT = -6 Other connection error
- ERR_UNKNOWN = -7 Unknown error occured
- ERR_INSUFFICANT_ARGS = -8 Wrong param number passed
- [/CODE]
- [/quote]
- Every function now returns this number as first and a describing String as second number.
- [quote name='Aichan' timestamp='1358812827' post='78548']
- 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
- [/quote]
- This piece of information is outdated. It still support string arguments for backwards compatibility but integers and booleans now work too
- [quote name='Aichan' timestamp='1358812827' post='78548']
- How do we read what is sent through the socket? What method?
- To read a socket, we do something a little bit different, we listen to triggered events.
- Different events are pulled by the peripheral here is a list I'll complete when I'll know them all :
- [CODE]
- "socket_line_received" Tells you a line has been received through the socket
- [/CODE]
- [/quote]
- In order to get This event you need to subscribe to the text event first. See above
- [quote name='Aichan' timestamp='1358812827' post='78548']
- [CODE]
- "socket_remote_closed" Tells you the socket has been remotely closed
- [/CODE]
- And here's a little example on how to read :
- [CODE]
- -- Waits for a line to be received
- local function readLine()
- while true do
- e, p1, p2 = os.pullEvent()
- if e == "socket_line_received" then
- return p2
- elseif e == "socket_remote_closed" then
- return nil
- end
- end
- end
- [/CODE]
- [/quote]
- 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