Return | Params | Description |
---|---|---|
Constructor | init(Pointer ptr) |
Constructor for the Socket object. |
Void | connect(String addr, Number port) |
Connects the socket to a given address through a given port. If the address is a URL, it selects the URL's corresponding IP address. |
Void | send(Any value) |
Sends data through the socket, automatically converted into a string. |
String | receive(Number bytes = 512, Lambda callback = null) |
Receives data up to a given amount of bytes from server. If no callback is given, the function waits until it recieves a response and then returns the function. If a callback is given, it detaches the receiving function from the main thread and calls the callback when it receives the answer, passing the value to the callback. |
Void | listen(Lambda callback, Number bytes = 512, Number blocking = false) |
Listens continuously through the socket, referring to a callback function whenever it receives data. By default it operates on a separate thread, but can be specified to block the main thread while it receives. Only ends when the connection breaks. |
Void | shutdown() |
Shutsdown a Socket's connection. |