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.
Fork of Controle_ventilo_ethernet_v1_2_4 by
main.cpp
- Committer:
- Brutus
- Date:
- 2016-11-18
- Revision:
- 2:1dd0818af42e
- Parent:
- 1:179393386b47
- Child:
- 3:6c54aa6db861
File content as of revision 2:1dd0818af42e:
#include "mbed.h" #include "EthernetInterface.h" #include "Ethernet.h" /*#include "TCPSocket.h" #include "TCPServer.h"*/ #include "SocketAddress.h" #include "Socket.h" #include "UDPSocket.h" const char* ECHO_SERVER_ADDRESS = "192.168.2.2"; const int ECHO_SERVER_PORT = 7; int main() { EthernetInterface eth; eth.Ethernet(); // problème lib ethernet eth.connect(); printf("\nClient IP Address is %s \n", eth.get_ip_address()); UDPSocket sock; sock.UDPSocket(); // problème lib UDPSocket SocketAddress echo_server; echo_server.set_ip_address(ECHO_SERVER_ADDRESS); echo_server.set_port(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.recvfrom(&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) {} } // code python /* import socket import signal import sys def signal_handler(signal, frame): print 'You pressed Ctrl+C!' sock.close() sys.exit(0) signal.signal(signal.SIGINT, signal_handler) ECHO_PORT = 7 print 'Server Running at ', socket.gethostbyname(socket.gethostname()) sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.bind(('', ECHO_PORT)) while True: print "waiting for UDP data packet..." data, address = sock.recvfrom(256) print "Received packet from", address, "with data",data print "Sending packet back to client" sock.sendto(data, address) */