oijoijoij

Dependencies:   EthernetInterface mbed-rtos mbed

Fork of TCPSocket_HelloWorld by mbed official

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers server.cpp Source File

server.cpp

00001 /*#include "mbed.h"
00002 #include "EthernetInterface.h"
00003  
00004 #define ECHO_SERVER_PORT   54321
00005  
00006 #define IP "192.168.0.10"
00007 #define GATEWAY "192.168.0.1"
00008 #define MASK "255.255.255.0"
00009  
00010 #define LEN 18980
00011 uint16_t sample_array0[LEN];
00012  
00013 DigitalOut led_red(LED_RED);
00014 DigitalOut led_green(LED_GREEN);
00015 DigitalOut led_blue(LED_BLUE);
00016  
00017 Serial pc(USBTX,USBRX);
00018  
00019 int main (void) {
00020     for(int i = 0; i < LEN; i++) sample_array0[i] = ((0x0031<<8) | 0x0032);
00021     sample_array0[0] = ('S'<<8)|'S';
00022     sample_array0[LEN-1] = ('F'<<8) | 'F';
00023     pc.baud(9600);
00024     pc.printf("Starting test server\r\n");
00025     
00026     EthernetInterface eth;
00027     eth.init(IP, MASK, GATEWAY);
00028     eth.connect();
00029     pc.printf("IP Address is %s\r\n", eth.getIPAddress());
00030     
00031     TCPSocketServer server;
00032     server.bind(ECHO_SERVER_PORT);
00033     server.listen();
00034     
00035     led_blue = 1;
00036     led_green = 1;
00037     led_red = 1;
00038     
00039     while (true) {
00040         //pc.printf("\r\nWait for new connection...\r\n");
00041         
00042         
00043         TCPSocketConnection client;
00044         server.accept(client);
00045         client.set_blocking(true, 5000);
00046             
00047         //pc.printf("Connection from: %s\r\n", client.get_address());
00048         char buffer[1460]; // size of IP payload
00049         while (true) {
00050             int n = client.receive(buffer, sizeof(buffer));
00051             if (n <= 0) break;
00052             pc.printf("Rec: %i: ",n);
00053             
00054  
00055             n = client.send_all((char *)sample_array0, LEN*2);
00056             
00057             if (n <= 0) {led_blue = 0; break;}
00058             pc.printf("Sent %i: ",n);
00059         }
00060         
00061         client.close();
00062         pc.printf("\r\n");
00063     }
00064 }*/