class socket – network socket¶
socket is an object that represents a network socket. Example usage:
socket = esp.socket()
socket.onrecv(print)
socket.connect(('207.58.139.247', 80))
socket.send('GET /testwifi/index.html HTTP/1.0\r\n\r\n')
TCP Methods¶
- 
socket.connect(addr)¶
- Connect to the adress and port specified in the - addrtuple.
- 
socket.close()¶
- Close the connection. 
- 
socket.accept()¶
- Accept a single connection from the connection queue. 
- 
socket.listen(backlog)¶
- Start listening for incoming connections. - Note: Only one socket can be listening for connections at a time. 
- 
socket.bind(addr)¶
- Bind the socket to the address and port specified by the - addrtuple.
- 
socket.send(buf)¶
- Send the bytes from - buf.
- 
socket.recv()¶
- Receive and return bytes from the socket. 
UDP Methods¶
- 
socket.sendto(data, addr)¶
- Placeholder for UDP support, not implemented yet. 
- 
socket.recvfrom(addr)¶
- Placeholder for UDP support, not implemented yet. 
Callback Setter Methods¶
- 
onconnect(lambda)::
- When connection is established, call the callback - lambda.
- 
onrecv(lambda)::
- When data is received, call the callback - lambda.
- 
onsent(lamda)::
- What data is finished sending, call the callback - lambda.
- 
ondisconnect(lambda)::
- Call the callback - lambdawhen the connection is closed.