demo versie 16/05

Dependencies:   EthernetInterface mbed-rto mbed

Fork of ProjectVLC by Klaas Govaerts

TCPlistener.cpp

Committer:
KlaasGovaerts
Date:
2018-04-18
Revision:
20:4997b02d6a88
Parent:
19:5ee34e60a31d
Child:
21:fe6a58e84929

File content as of revision 20:4997b02d6a88:

#include "TCPlistener.h"

TCPlistener::TCPlistener(){
    char ip[]="192.168.0.253";
    char mask[]="255.255.255.0";
    char gateway[]="192.168.0.254";
    eth.init(ip,mask,gateway);
    eth.connect();
    server.bind(4000);
    server.listen();
    server.set_blocking(true);
    /*
    for(int i=0;i<10;i++){
        connections[i]=0;
    }*/
    arraySize=10;
}
/*
void TCPlistener::listen(){
    //server.listen(10);//Accept 10 connections at a time.
    //Source:https://os.mbed.com/handbook/Socket
    bool incomingConnection=true;
    while(incomingConnection){
        TCPSocketConnection* connection=newConnection();
        if(connection!=0){
            if(server.accept(*connection)==-1)
                incomingConnection=false;
            else
                connection->set_blocking(false);
                printf("Connectie van: %s\n", connection->get_address());
        }
    }
}*/

bool TCPlistener::receiveSegment(char *contents,int size){
    printf("Maak een connectie.\r\n");
    TCPSocketConnection client;
    server.accept(client);
    int n=client.receive(contents,size);   
    if(n!=-1){
        contents[n] = '\0';
        printf("Segment ontvangen van %s:%i met inhoud \"%s\"\r\n", client.get_address(),client.get_port(),contents);
        return true;
    }
    return false;
}