demo versie 16/05

Dependencies:   EthernetInterface mbed-rto mbed

Fork of ProjectVLC by Klaas Govaerts

Committer:
KlaasGovaerts
Date:
Wed May 02 06:53:40 2018 +0000
Revision:
35:efdbfccf2678
Parent:
31:915f6cb7ffa5
Child:
36:aa6c6c177be2
Added documentation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
KlaasGovaerts 5:0413d42377d1 1 #include "TCPlistener.h"
KlaasGovaerts 5:0413d42377d1 2
KlaasGovaerts 35:efdbfccf2678 3 /**
KlaasGovaerts 35:efdbfccf2678 4 * Initialise with ip address of 192.168.0.253, a mask of 255.255.255.0 and a gateway of 192.168.0.254.
KlaasGovaerts 35:efdbfccf2678 5 * Starts a TCP server which will listen on port 4000.
KlaasGovaerts 35:efdbfccf2678 6 */
KlaasGovaerts 5:0413d42377d1 7 TCPlistener::TCPlistener(){
KlaasGovaerts 31:915f6cb7ffa5 8 char ip[]="192.168.0.253";
KlaasGovaerts 31:915f6cb7ffa5 9 char mask[]="255.255.255.0";
KlaasGovaerts 31:915f6cb7ffa5 10 char gateway[]="192.168.0.254";
KlaasGovaerts 5:0413d42377d1 11 eth.init(ip,mask,gateway);
KlaasGovaerts 5:0413d42377d1 12 eth.connect();
KlaasGovaerts 5:0413d42377d1 13 server.bind(4000);
KlaasGovaerts 16:ffd311730575 14 server.listen();
KlaasGovaerts 20:4997b02d6a88 15 server.set_blocking(true);
KlaasGovaerts 15:5f1fda6b9140 16 arraySize=10;
KlaasGovaerts 5:0413d42377d1 17 }
KlaasGovaerts 13:f3db7045e220 18
KlaasGovaerts 35:efdbfccf2678 19 /**
KlaasGovaerts 35:efdbfccf2678 20 * Receives all packets sent to 192.168.0.253:4000. The receive is non blocking.
KlaasGovaerts 35:efdbfccf2678 21 * @param contents The location where the segment contents will be written, formatted as null terminated character array.
KlaasGovaerts 35:efdbfccf2678 22 * @param size The max size of the "contents" array.
KlaasGovaerts 35:efdbfccf2678 23 * @return True if a segment was received, false if no segment was received.
KlaasGovaerts 35:efdbfccf2678 24 */
KlaasGovaerts 16:ffd311730575 25 bool TCPlistener::receiveSegment(char *contents,int size){
KlaasGovaerts 20:4997b02d6a88 26 printf("Maak een connectie.\r\n");
KlaasGovaerts 20:4997b02d6a88 27 TCPSocketConnection client;
KlaasGovaerts 20:4997b02d6a88 28 server.accept(client);
KlaasGovaerts 20:4997b02d6a88 29 int n=client.receive(contents,size);
KlaasGovaerts 20:4997b02d6a88 30 if(n!=-1){
KlaasGovaerts 20:4997b02d6a88 31 contents[n] = '\0';
KlaasGovaerts 20:4997b02d6a88 32 printf("Segment ontvangen van %s:%i met inhoud \"%s\"\r\n", client.get_address(),client.get_port(),contents);
KlaasGovaerts 20:4997b02d6a88 33 return true;
KlaasGovaerts 16:ffd311730575 34 }
KlaasGovaerts 16:ffd311730575 35 return false;
KlaasGovaerts 19:5ee34e60a31d 36 }