First version
Dependencies: mbed EthernetInterface mbed-rto
Diff: TCPlistener.cpp
- Revision:
- 12:f3db7045e220
- Parent:
- 4:0413d42377d1
- Child:
- 13:a6c651a1e51c
--- a/TCPlistener.cpp Wed Mar 28 14:19:06 2018 +0000 +++ b/TCPlistener.cpp Wed Apr 18 07:41:38 2018 +0000 @@ -7,9 +7,42 @@ eth.init(ip,mask,gateway); eth.connect(); server.bind(4000); + server.set_blocking(false); + for(int i=0;i<10;i++){ + connections[i]=0; + } } +void TCPlistener::listen(){ + server.listen(10);//Accept 10 connections at a time. + //Source:https://os.mbed.com/handbook/Socket + + bool searchLocation=true; + for(int i=0;i<10&&searchLocation;i++){ + if(connections[i]!=0){ + connections[i]=new TCPSocketConnection(); + + searchLocation=false; + } + } + + bool incomingConnection=true; + while(incomingConnection){ + server.accept(client); + } + //client.set_blocking(false, 100); + + + printf("Connection from: %s\n", client.get_address()); + + +} + void TCPlistener::receivePacket(char *contents,int size){ - int n = server.recv(contents, size); + int n = server.receive(contents, size); contents[n] = '\0'; printf("Segment ontvangen van %s:%i met inhoud \"%s\"\r\n", client.get_address(),client.get_port(),contents); +} + +void TCPlistener::firstEmptyLocation(){ + } \ No newline at end of file