kore-doc

The kore documentation found under https://docs.kore.io/
Commits | Files | Refs | README | git clone https://git.kore.io/kore-doc.git

commit 7032efd145750f0d72bb96682e277aace3050ddc
parent f629aeebaf9b80b9bf533ccd8b290f608ef6ab5f
Author: Joris Vink <joris@coders.se>
Date:   Mon, 21 Jan 2019 15:28:35 +0100

add recvfrom()/sendto()

Diffstat:
api/python.md | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 67 insertions(+), 0 deletions(-)

diff --git a/api/python.md b/api/python.md @@ -869,7 +869,9 @@ socket. When you have a wrapped socket you can connect/accept, send or recv asynchronously. * [recv](#socketrecv) +* [recvfrom](#socketrecvfrom) * [send](#socketsend) +* [sendto](#socketsendto) * [accept](#socketaccept) * [connect](#socketconnect) * [close](#socketclose) @@ -932,6 +934,39 @@ else: --- +### sock.recvfrom {#socketrecvfrom} + +### Synopsis + +```python +address, port, data = await sock.recvfrom(1024) +``` + +### Description + +Reads up to **maxlen** bytes from the socket while returning the source +ip and source port. + +| Parameter | Description | +| --- | --- | +| maxlen | Maximum number of bytes to be read. | + +### Returns + +A tuple of (adress, port, data) or None on EOF. + +### Example + +```python +ip, port, bytes = await sock.recvfrom(1024) +if bytes is None: + printf("eof!") +else: + sock.sendto(ip, port, bytes) +``` + +--- + ### sock.send {#socketsend} ### Synopsis @@ -962,6 +997,38 @@ await sock.send("Hello world") --- +### sock.sendto {#socketsendto} + +### Synopsis + +```python +await sock.sendto(address, port, data) +``` + +### Description + +Sends the given data over the socket to the specified destination. + +| Parameter | Description | +| --- | --- | +| address | The destination IP address. | +| port | The destination port. | +| data | The data to be sent (as bytes). | + +### Returns + +Nothing. In case the peer closes the socket before all data is written +a RuntimeException is thrown. + +### Example + +```python +# Will return when all bytes are sent. +await sock.send("127.0.0.1", "3311", "Hello world") +``` + +--- + ### sock.accept {#socketaccept} ### Synopsis