Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: M2X_dev axeda_wrapper_dev MTS_M2x_Example1 MTS_Cellular_Connect_Example ... more
Diff: tests/test_TCP_Socket.h
- Revision:
- 19:38794784e009
- Child:
- 39:6e94520a3217
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_TCP_Socket.h Mon Dec 16 23:02:22 2013 +0000
@@ -0,0 +1,70 @@
+#ifndef _TEST_TCP_SOCKET_H_
+#define _TEST_TCP_SOCKET_H_
+
+void testTcpSocket() {
+ Cellular::Code code;
+ const int TEST_PORT = 7000;
+ const std::string TEST_SERVER("204.26.122.5");
+
+ printf("TCP SOCKET TESTING\r\n");
+ printf("Setting APN\r\n");
+ code = Cellular::getInstance()->setApn("b2b.tmobile.com");
+ if(code == Cellular::OK) {
+ printf("Success!\r\n");
+ } else {
+ printf("Error during APN setup [%d]\r\n", (int)code);
+ }
+
+ printf("Setting Socket Closeable\r\n");
+ code = Cellular::getInstance()->setSocketCloseable();
+ if(code == Cellular::OK) {
+ printf("Success!\r\n");
+ } else {
+ printf("Error setting socket closeable [%d]\r\n", (int)code);
+ }
+
+ printf("Establishing PPP Connection\r\n");
+ if(Cellular::getInstance()->connect()) {
+ printf("Success!\r\n");
+ } else {
+ printf("Error during PPP connection\r\n");
+ }
+
+ printf("Opening a TCP Socket\r\n");
+ if(Cellular::getInstance()->open(TEST_SERVER, TEST_PORT, IPStack::TCP)) {
+ printf("Success!\r\n");
+ } else {
+ printf("Error during TCP socket open [%s:%d]\r\n", TEST_SERVER.c_str(), TEST_PORT);
+ }
+
+ printf("Reading from socket for 15 seconds\r\n");
+ char data[1024] = { 0 };
+ int bytesRead = Cellular::getInstance()->read(data, 1023, 15000); //1 less than max
+ printf("READ: [%d] [%s]\r\n", bytesRead, data);
+
+
+ printf("Waiting 10 seconds\r\n");
+ wait(10);
+
+ printf("Writing to socket\r\n");
+ sprintf(data, "3\r\n");
+ int bytesWritten = Cellular::getInstance()->write(data, 4, 10000);
+ if(bytesWritten == 4) {
+ printf("Successfully wrote 'q'\r\n");
+ } else {
+ printf("Failed to write 'q'\r\n");
+ }
+
+ printf("Reading from socket for 15 seconds\r\n");
+ bytesRead = Cellular::getInstance()->read(data, 1023, 15000); //1 less than max
+ printf("READ: [%d] [%s]\r\n", bytesRead, data);
+
+ printf("Closing socket\r\n");
+ Cellular::getInstance()->close();
+
+
+ printf("Disconnecting\r\n");
+ Cellular::getInstance()->disconnect();
+}
+
+#endif
uIP Socket Modem Shield (Outdated - see below)