![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
demo versie 16/05
Dependencies: EthernetInterface mbed-rto mbed
Fork of ProjectVLC by
Diff: TCPlistener.cpp
- Revision:
- 14:a6c651a1e51c
- Parent:
- 13:f3db7045e220
- Child:
- 15:5f1fda6b9140
--- a/TCPlistener.cpp Wed Apr 18 07:41:38 2018 +0000 +++ b/TCPlistener.cpp Wed Apr 18 08:09:56 2018 +0000 @@ -9,24 +9,16 @@ server.bind(4000); server.set_blocking(false); for(int i=0;i<10;i++){ - connections[i]=0; + connections[i]=new TCPSocketConnection(); } } 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){ + TCPSocketConnection *connection=newConnection(); server.accept(client); } //client.set_blocking(false, 100); @@ -43,6 +35,25 @@ 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 +TCPSocketConnection * TCPlistener::newConnection(TCPSocketConnection **connectionArray,int arraySize){ + bool searchLocation=true; + for(int i=0;i<arraySize&&searchLocation;i++){ + if(connectionArray[i]==0){ + connectionArray[i]=new TCPSocketConnection(); + return connectionArray[i]; + } else if(!(connectionArray[i]->is_connected())){ + delete connectionArray[i]; + connectionArray[i]=new TCPSocketConnection(); + return connectionArray[i]; + } + } + return 0; +} + +/* + if(){ + connections[i]=new TCPSocketConnection(); + + searchLocation=false; + } + */ \ No newline at end of file