![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
First version
Dependencies: mbed EthernetInterface mbed-rto
TCPlistener.cpp
- Committer:
- KlaasGovaerts
- Date:
- 2018-05-02
- Revision:
- 35:efdbfccf2678
- Parent:
- 30:915f6cb7ffa5
- Child:
- 36:aa6c6c177be2
File content as of revision 35:efdbfccf2678:
#include "TCPlistener.h" /** * Initialise with ip address of 192.168.0.253, a mask of 255.255.255.0 and a gateway of 192.168.0.254. * Starts a TCP server which will listen on port 4000. */ 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); arraySize=10; } /** * Receives all packets sent to 192.168.0.253:4000. The receive is non blocking. * @param contents The location where the segment contents will be written, formatted as null terminated character array. * @param size The max size of the "contents" array. * @return True if a segment was received, false if no segment was received. */ 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; }