demo versie 16/05

Dependencies:   EthernetInterface mbed-rto mbed

Fork of ProjectVLC by Klaas Govaerts

Committer:
KlaasGovaerts
Date:
Wed May 02 08:11:42 2018 +0000
Revision:
36:aa6c6c177be2
Parent:
33:2d4a2bfd0cd6
Parent:
35:efdbfccf2678
Child:
37:4589f962697d
Samengevoegde versie

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();
albireo987 33:2d4a2bfd0cd6 15 server.set_blocking(false,0);
KlaasGovaerts 36:aa6c6c177be2 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);
albireo987 32:537005b4a065 29 int n=client.receive(contents,size);
albireo987 33:2d4a2bfd0cd6 30 while(n==-1)
albireo987 32:537005b4a065 31 {
albireo987 32:537005b4a065 32 if(n!=-1){
albireo987 32:537005b4a065 33 contents[n] = '\0';
albireo987 32:537005b4a065 34 printf("Segment ontvangen van %s:%i met inhoud \"%s\"\r\n", client.get_address(),client.get_port(),contents);
albireo987 32:537005b4a065 35 return true;
albireo987 32:537005b4a065 36 }
albireo987 32:537005b4a065 37 }
KlaasGovaerts 16:ffd311730575 38 return false;
KlaasGovaerts 19:5ee34e60a31d 39 }