demo versie 16/05

Dependencies:   EthernetInterface mbed-rto mbed

Fork of ProjectVLC by Klaas Govaerts

Committer:
KlaasGovaerts
Date:
Wed Apr 18 07:41:38 2018 +0000
Revision:
13:f3db7045e220
Parent:
5:0413d42377d1
Child:
14:a6c651a1e51c
Versie 18/04

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 13:f3db7045e220 10 server.set_blocking(false);
KlaasGovaerts 13:f3db7045e220 11 for(int i=0;i<10;i++){
KlaasGovaerts 13:f3db7045e220 12 connections[i]=0;
KlaasGovaerts 13:f3db7045e220 13 }
KlaasGovaerts 5:0413d42377d1 14 }
KlaasGovaerts 13:f3db7045e220 15 void TCPlistener::listen(){
KlaasGovaerts 13:f3db7045e220 16 server.listen(10);//Accept 10 connections at a time.
KlaasGovaerts 13:f3db7045e220 17 //Source:https://os.mbed.com/handbook/Socket
KlaasGovaerts 13:f3db7045e220 18
KlaasGovaerts 13:f3db7045e220 19 bool searchLocation=true;
KlaasGovaerts 13:f3db7045e220 20 for(int i=0;i<10&&searchLocation;i++){
KlaasGovaerts 13:f3db7045e220 21 if(connections[i]!=0){
KlaasGovaerts 13:f3db7045e220 22 connections[i]=new TCPSocketConnection();
KlaasGovaerts 13:f3db7045e220 23
KlaasGovaerts 13:f3db7045e220 24 searchLocation=false;
KlaasGovaerts 13:f3db7045e220 25 }
KlaasGovaerts 13:f3db7045e220 26 }
KlaasGovaerts 13:f3db7045e220 27
KlaasGovaerts 13:f3db7045e220 28 bool incomingConnection=true;
KlaasGovaerts 13:f3db7045e220 29 while(incomingConnection){
KlaasGovaerts 13:f3db7045e220 30 server.accept(client);
KlaasGovaerts 13:f3db7045e220 31 }
KlaasGovaerts 13:f3db7045e220 32 //client.set_blocking(false, 100);
KlaasGovaerts 13:f3db7045e220 33
KlaasGovaerts 13:f3db7045e220 34
KlaasGovaerts 13:f3db7045e220 35 printf("Connection from: %s\n", client.get_address());
KlaasGovaerts 13:f3db7045e220 36
KlaasGovaerts 13:f3db7045e220 37
KlaasGovaerts 13:f3db7045e220 38 }
KlaasGovaerts 13:f3db7045e220 39
KlaasGovaerts 5:0413d42377d1 40 void TCPlistener::receivePacket(char *contents,int size){
KlaasGovaerts 13:f3db7045e220 41 int n = server.receive(contents, size);
KlaasGovaerts 5:0413d42377d1 42 contents[n] = '\0';
KlaasGovaerts 5:0413d42377d1 43 printf("Segment ontvangen van %s:%i met inhoud \"%s\"\r\n", client.get_address(),client.get_port(),contents);
KlaasGovaerts 13:f3db7045e220 44 }
KlaasGovaerts 13:f3db7045e220 45
KlaasGovaerts 13:f3db7045e220 46 void TCPlistener::firstEmptyLocation(){
KlaasGovaerts 13:f3db7045e220 47
KlaasGovaerts 5:0413d42377d1 48 }