Base class for IP Based Networking Libraries

Dependencies:   DnsQuery

Dependents:   TempTower BSDInterfaceTests HelloBSDInterface ESP8266InterfaceTests ... more

For a complete getting started guide see the wiki...

Network Socket API

The Network Socket API provides a common interface for using sockets on network devices. The API provides a simple class-based interface that should be familiar to users experienced with other socket APIs. Additionally, the API provides a simple interface for implementing network devices, making it easy to connect hardware agnostic programs to new devices.

Network Interfaces

The NetworkInterface provides an abstract class for network devices that support sockets. Devices should provide a DeviceInterface class that inherits this interface and adds implementation specific methods for using the device. A NetworkInterface must be provided to a Socket constructor to open a socket on the interface. Currently two subclasses are defined for common devices, EthernetInterface and WiFiInterface.

Sockets

The Socket class is used for managing network sockets. Once opened, the socket provides a pipe through which data can sent and recieved to a specific endpoint. The socket class can be instantiated as either a TCPSocket or a UDPSocket which defines the protocol used for the connection.

Branch:
api-changes
Revision:
41:3ec1c97e9bbf
Parent:
38:157fb2ab965f
Child:
42:49893d13c432
--- a/Socket.h	Mon Feb 22 23:52:09 2016 -0600
+++ b/Socket.h	Tue Feb 23 04:01:38 2016 -0600
@@ -53,6 +53,16 @@
      */
     uint16_t getPort() const;
 
+    /** Set a timeout on network operations
+     *  @param timeout Maximum time in milliseconds for socket operations
+     */
+    void setTimeout(uint32_t timeout);
+
+    /** Get the current timeout on network operations
+     *  @return Maximum time in milliseconds for socket operations
+     */
+    uint32_t getTimeout() const;
+
     /** Returns status of socket
      *  @return true if connected
      */
@@ -74,18 +84,16 @@
     /** Send data over the socket
      *  @param data Buffer of data to send
      *  @param len Size of data to send
-     *  @param timeout_ms Maximum amount of time to wait
      *  @return 0 on success
      */
-    int32_t send(const void *data, uint32_t len, uint32_t timeout_ms = 15000);
+    int32_t send(const void *data, uint32_t len);
 
     /** Recieve data over the socket
      *  @param data Buffer to store recieved data
      *  @param len Size of provided buffer
-     *  @param timeout_ms Maximum amount of time to wait
      *  @return Number of bytes sent or a negative value on failure
      */
-    int32_t recv(void *data, uint32_t len, uint32_t timeout_ms = 15000);
+    int32_t recv(void *data, uint32_t len);
 
 
 protected:
@@ -99,6 +107,7 @@
 
     char _ip_address[SOCK_IP_SIZE];
     uint16_t _port;
+    uint32_t _timeout;
 };
 
 #endif