A library for talking to Multi-Tech's Cellular SocketModem Devices.
Dependents: M2X_dev axeda_wrapper_dev MTS_M2x_Example1 MTS_Cellular_Connect_Example ... more
Diff: tests/test_UDP_Socket.h
- Revision:
- 124:6d964b4343c8
- Parent:
- 121:5a7fba896c98
- Child:
- 125:850c51cbeff7
--- a/tests/test_UDP_Socket.h Tue Dec 31 23:41:59 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,106 +0,0 @@ -#ifndef _TEST_UDP_SOCKET_ECHO_H_ -#define _TEST_UDP_SOCKET_ECHO_H_ - - -//Setup a netcat server with command: ncat -l 5798 -k -c 'xargs -n1 --null echo' - -void testUdpSocket() { - using namespace mts; - - Code code; - const int TEST_PORT = 5798; - const std::string TEST_SERVER("204.26.122.96"); - const char buffer[] = "*ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890*"; - const int size = sizeof(buffer); - char receiveBuffer[size]; - - printf("UDP SOCKET TESTING\r\n"); - printf("Setting APN\r\n"); - code = Cellular::getInstance()->setApn("b2b.tmobile.com"); - if(code == SUCCESS) { - 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 == SUCCESS) { - printf("Success!\r\n"); - } else { - printf("Error setting socket closeable [%d]\r\n", (int)code); - } - - printf("Setting Local Port\r\n"); - if(Cellular::getInstance()->bind(5000)) { - printf("Success!\r\n"); - } else { - printf("Error setting local port [%d]\r\n", (int)code); - } - - printf("Setting Primary DNS\r\n"); - code = Cellular::getInstance()->setDns("8.8.8.8"); - if(code == SUCCESS) { - printf("Success!\r\n"); - } else { - printf("Error setting primary DNS [%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. Aborting.\r\n"); - return; - } - - printf("Opening a UDP Socket\r\n"); - if(Cellular::getInstance()->open(TEST_SERVER, TEST_PORT, IPStack::UDP)) { - printf("Success!\r\n"); - } else { - printf("Error during UDP socket open [%s:%d]. Aborting.\r\n", TEST_SERVER.c_str(), TEST_PORT); - return; - } - - printf("Sending buffer\r\n"); - int bytesWritten = Cellular::getInstance()->write(buffer, size, 10000); - if(bytesWritten == size) { - printf("Successfully sent buffer\r\n"); - } else { - printf("Failed to send buffer. Closing socket and aborting.\r\n"); - Cellular::getInstance()->close(); - return; - } - - printf("Receiving echo (timeout = 15 seconds)\r\n"); - Timer tmr; - int bytesRead = 0; - tmr.start(); - do { - int status = Cellular::getInstance()->read(&receiveBuffer[bytesRead], size - bytesRead, 1000); - if(status != -1) { - bytesRead += status; - } else { - printf("Error reading from socket. Closing socket and aborting.\r\n"); - Cellular::getInstance()->close(); - return; - } - printf("Total bytes read %d\r\n", bytesRead); - } while (tmr.read_ms() <= 15000 && bytesRead < size); - - - //Safely Cap at Max Size - receiveBuffer[size - 1] = '\0'; - printf("Comparing Buffers\r\n"); - printf("SENT: [%s]\r\n", buffer); - printf("RECV: [%s]\r\n", receiveBuffer); - - printf("Closing socket\r\n"); - Cellular::getInstance()->close(); - - - printf("Disconnecting\r\n"); - Cellular::getInstance()->disconnect(); -} - -#endif