demo versie 16/05

Dependencies:   EthernetInterface mbed-rto mbed

Fork of ProjectVLC by Klaas Govaerts

Committer:
KlaasGovaerts
Date:
Wed Apr 18 13:58:46 2018 +0000
Revision:
20:4997b02d6a88
Parent:
19:5ee34e60a31d
Child:
21:fe6a58e84929
Versie 16:00

Who changed what in which revision?

UserRevisionLine numberNew contents of line
KlaasGovaerts 5:0413d42377d1 1 #include "TCPlistener.h"
KlaasGovaerts 5:0413d42377d1 2
KlaasGovaerts 5:0413d42377d1 3 TCPlistener::TCPlistener(){
KlaasGovaerts 5:0413d42377d1 4 char ip[]="192.168.0.253";
KlaasGovaerts 5:0413d42377d1 5 char mask[]="255.255.255.0";
KlaasGovaerts 5:0413d42377d1 6 char gateway[]="192.168.0.254";
KlaasGovaerts 5:0413d42377d1 7 eth.init(ip,mask,gateway);
KlaasGovaerts 5:0413d42377d1 8 eth.connect();
KlaasGovaerts 5:0413d42377d1 9 server.bind(4000);
KlaasGovaerts 16:ffd311730575 10 server.listen();
KlaasGovaerts 20:4997b02d6a88 11 server.set_blocking(true);
KlaasGovaerts 20:4997b02d6a88 12 /*
KlaasGovaerts 13:f3db7045e220 13 for(int i=0;i<10;i++){
KlaasGovaerts 15:5f1fda6b9140 14 connections[i]=0;
KlaasGovaerts 20:4997b02d6a88 15 }*/
KlaasGovaerts 15:5f1fda6b9140 16 arraySize=10;
KlaasGovaerts 5:0413d42377d1 17 }
KlaasGovaerts 20:4997b02d6a88 18 /*
KlaasGovaerts 13:f3db7045e220 19 void TCPlistener::listen(){
KlaasGovaerts 15:5f1fda6b9140 20 //server.listen(10);//Accept 10 connections at a time.
KlaasGovaerts 13:f3db7045e220 21 //Source:https://os.mbed.com/handbook/Socket
KlaasGovaerts 13:f3db7045e220 22 bool incomingConnection=true;
KlaasGovaerts 13:f3db7045e220 23 while(incomingConnection){
KlaasGovaerts 16:ffd311730575 24 TCPSocketConnection* connection=newConnection();
KlaasGovaerts 16:ffd311730575 25 if(connection!=0){
KlaasGovaerts 16:ffd311730575 26 if(server.accept(*connection)==-1)
KlaasGovaerts 16:ffd311730575 27 incomingConnection=false;
KlaasGovaerts 16:ffd311730575 28 else
KlaasGovaerts 16:ffd311730575 29 connection->set_blocking(false);
KlaasGovaerts 16:ffd311730575 30 printf("Connectie van: %s\n", connection->get_address());
KlaasGovaerts 16:ffd311730575 31 }
KlaasGovaerts 13:f3db7045e220 32 }
KlaasGovaerts 20:4997b02d6a88 33 }*/
KlaasGovaerts 13:f3db7045e220 34
KlaasGovaerts 16:ffd311730575 35 bool TCPlistener::receiveSegment(char *contents,int size){
KlaasGovaerts 20:4997b02d6a88 36 printf("Maak een connectie.\r\n");
KlaasGovaerts 20:4997b02d6a88 37 TCPSocketConnection client;
KlaasGovaerts 20:4997b02d6a88 38 server.accept(client);
KlaasGovaerts 20:4997b02d6a88 39 int n=client.receive(contents,size);
KlaasGovaerts 20:4997b02d6a88 40 if(n!=-1){
KlaasGovaerts 20:4997b02d6a88 41 contents[n] = '\0';
KlaasGovaerts 20:4997b02d6a88 42 printf("Segment ontvangen van %s:%i met inhoud \"%s\"\r\n", client.get_address(),client.get_port(),contents);
KlaasGovaerts 20:4997b02d6a88 43 return true;
KlaasGovaerts 16:ffd311730575 44 }
KlaasGovaerts 16:ffd311730575 45 return false;
KlaasGovaerts 19:5ee34e60a31d 46 }