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.

Revision:
58:1caa187fa5af
Parent:
57:3c873fab4207
Child:
63:531f4c27f360
--- a/Socket.h	Thu Feb 25 19:00:39 2016 -0600
+++ b/Socket.h	Thu Feb 25 21:20:25 2016 -0600
@@ -28,45 +28,13 @@
 public:
     ~Socket();
 
-    /** Set the URL of the socket
-     *  Performs DNS lookup if necessary
-     *  @param url URL to connect to
+
+    /** Open a connection to the underlying address
+     *  @param address URL or IP address to connect to
+     *  @param port Port to connect to
      *  @return 0 on success
      */
-    int32_t setURL(const char *url);
-
-    /** Set the IP address of the socket
-     *  @param ip IP address to connect to, copied internally
-     */
-    void setIPAddress(const char *ip);
-
-    /** Set the port of the socket
-     *  @param port Port to connect to
-     */
-    void setPort(uint16_t port);
-
-    /** Gets the IP address
-     *  @return IP address to connect to
-     */
-    const char *getIPAddress() const;
-
-    /** Gets the port
-     *  @return Port to connect to
-     */
-    uint16_t getPort() const;
-
-    /** Returns status of socket
-     *  @return true if connected
-     */
-    bool isConnected();
-
-
-    /** Open a connection to the underlying address
-     *  @param address Optional URL or IP address to connect to
-     *  @param port Optional port to connect to
-     *  @return 0 on success
-     */
-    int32_t open(const char *address = 0, uint16_t port = 0);
+    int32_t open(const char *address, uint16_t port);
 
     /** Close an open connection
      *  @return 0 on success
@@ -89,6 +57,22 @@
     int32_t recv(void *data, uint32_t size, bool blocking = true);
 
 
+    /** Gets the IP address
+     *  @return IP address to connect to
+     */
+    const char *getIPAddress() const;
+
+    /** Gets the port
+     *  @return Port to connect to
+     */
+    uint16_t getPort() const;
+
+    /** Returns status of socket
+     *  @return true if connected
+     */
+    bool isConnected();
+
+
 protected:
     Socket(NetworkInterface *iface, ns_protocol_t proto);