test
Dependencies: C12832 EthernetInterface mbed-rtos mbed
Fork of UDPEchoClient by
Revision 9:42a7f24bd00c, committed 2015-06-17
- Comitter:
- rezafirouzi
- Date:
- Wed Jun 17 21:12:25 2015 +0000
- Parent:
- 8:ae11db01fb2d
- Commit message:
- test
Changed in this revision
diff -r ae11db01fb2d -r 42a7f24bd00c C12832.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/C12832.lib Wed Jun 17 21:12:25 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/askksa12543/code/C12832/#990d5eec2ef6
diff -r ae11db01fb2d -r 42a7f24bd00c main.cpp --- a/main.cpp Tue May 05 20:08:56 2015 +0000 +++ b/main.cpp Wed Jun 17 21:12:25 2015 +0000 @@ -1,33 +1,13 @@ -#include "mbed.h" -#include "EthernetInterface.h" - -const char* ECHO_SERVER_ADDRESS = "192.168.2.2"; -const int ECHO_SERVER_PORT = 7; - -int main() { - EthernetInterface eth; - eth.init(); //Use DHCP - eth.connect(); - printf("\nClient IP Address is %s \n", eth.getIPAddress()); - - UDPSocket sock; - sock.init(); - - Endpoint echo_server; - echo_server.set_address(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT); - - char out_buffer[] = "Hello World"; - printf("Sending message '%s' to server (%s)\n",out_buffer,ECHO_SERVER_ADDRESS); - sock.sendTo(echo_server, out_buffer, sizeof(out_buffer)); - - char in_buffer[256]; - int n = sock.receiveFrom(echo_server, in_buffer, sizeof(in_buffer)); - - in_buffer[n] = '\0'; - printf("Received message from server: '%s'\n", in_buffer); - - sock.close(); - - eth.disconnect(); - while(1) {} +#include <stdlib.h> +#include "lib_socket.h" + +int main(){ + const char* ipAddress = "130.237.53.141"; + const int port = 102; + + char* out_buffer =(char *)calloc(50,sizeof(char)); + out_buffer = "Hi Albert...How are you?"; + + send_message_UDP(out_buffer, ipAddress, port); + return 0; } \ No newline at end of file
diff -r ae11db01fb2d -r 42a7f24bd00c src/lib_socket.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib_socket.cpp Wed Jun 17 21:12:25 2015 +0000 @@ -0,0 +1,32 @@ +#include "mbed.h" +#include "EthernetInterface.h" +#include "C12832.h" +#include "lib_socket.h" + +C12832 lcd(p5, p7, p6, p8, p11); + +void send_message_UDP(char* buffer, const char* ipAdsress, const int port) { + + EthernetInterface eth; + eth.init(); //Use DHCP + eth.connect(); + + lcd.cls(); + lcd.locate(0,1); + lcd.printf("Client IP:%s \n", eth.getIPAddress()); + + UDPSocket sock; + sock.init(); + + Endpoint echo_server; + echo_server.set_address(ipAdsress, port); + + lcd.locate(0,10); + int m = sock.sendTo(echo_server, buffer, sizeof(buffer)); + lcd.printf("%d bytes of msg '%s' sent\n",m,buffer); + + sock.close(); + + eth.disconnect(); + while(1) {} +} \ No newline at end of file
diff -r ae11db01fb2d -r 42a7f24bd00c src/lib_socket.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib_socket.h Wed Jun 17 21:12:25 2015 +0000 @@ -0,0 +1,6 @@ +#ifndef LIB_SOCKET_H_ +#define LIB_SOCKET_H_ + +void send_message_UDP(char* buffer, const char* ipAdsress, const int port); + +#endif /* LIB_SOCKET_H_ */ \ No newline at end of file