STM32F207
Dependencies: SN74CBT3257 Binary_Switch OSL10564_74HC595
Diff: main.cpp
- Revision:
- 0:ddb5698aa782
- Child:
- 1:74ecd404d5e5
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Mon Oct 30 16:59:55 2017 +0000
@@ -0,0 +1,38 @@
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "TCPServer.h"
+#include "TCPSocket.h"
+
+int main()
+{
+ printf("TCP server example\n");
+
+ EthernetInterface eth;
+ eth.connect();
+
+ printf("The Server IP address is '%s'\n", eth.get_ip_address());
+
+ TCPServer srv;
+ TCPSocket client_sock;
+ SocketAddress client_addr;
+ char *buffer = new char[256];
+
+ /* Open the server on ethernet stack */
+ srv.open(ð);
+
+ /* Bind the HTTP port (TCP 80) to the server */
+ srv.bind(eth.get_ip_address(), 23);
+
+ /* Can handle x simultaneous connections */
+ srv.listen(1);
+
+ srv.accept(&client_sock, &client_addr);
+ printf("Accepted %s:%d\n", client_addr.get_ip_address(),
+ client_addr.get_port());
+ strcpy(buffer, "Hello \n\r");
+ client_sock.send(buffer, strlen(buffer));
+ client_sock.recv(buffer, 256);
+
+ client_sock.close();
+ delete[] buffer;
+}