Socket library for MTS Socket Modem Arduino Shield devices from Multi-Tech Systems

Dependencies:   HTTPClient-SSL

Dependents:   mtsas mtsas mtsas mtsas_lat3

Revision:
9:b2e3862705fc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UDPSocket.cpp	Tue Jun 17 21:59:55 2014 +0000
@@ -0,0 +1,50 @@
+#include "UDPSocket.h"
+#include <string>
+#include <algorithm>
+
+UDPSocket::UDPSocket()
+{
+}
+
+int UDPSocket::init(void)
+{
+    return 0;
+}
+
+// Server initialization
+int UDPSocket::bind(int port)
+{
+    if (ip->bind(port)) {
+        return 0;
+    } else {
+        return -1;
+    }
+}
+
+// -1 if unsuccessful, else number of bytes written
+int UDPSocket::sendTo(Endpoint &remote, char *packet, int length)
+{
+    if (!ip->open(remote.get_address(), remote.get_port(), IPStack::UDP)) {
+        return -1;
+    }
+
+    if (_blocking) {
+        return ip->write(packet, length, -1);
+    } else {
+        return ip->write(packet, length, _timeout);
+    }
+}
+
+// -1 if unsuccessful, else number of bytes received
+int UDPSocket::receiveFrom(Endpoint &remote, char *buffer, int length)
+{
+    if (!ip->open(remote.get_address(), remote.get_port(), IPStack::UDP)) {
+        return -1;
+    }
+
+    if (_blocking) {
+        return ip->read(buffer, length, -1);
+    } else {
+        return ip->read(buffer, length, _timeout);
+    }
+}
\ No newline at end of file