demo versie 16/05
Dependencies: EthernetInterface mbed-rto mbed
Fork of ProjectVLC by
Diff: TCPlistener.cpp
- Revision:
- 16:ffd311730575
- Parent:
- 15:5f1fda6b9140
- Child:
- 19:5ee34e60a31d
--- a/TCPlistener.cpp Wed Apr 18 08:35:32 2018 +0000 +++ b/TCPlistener.cpp Wed Apr 18 09:17:14 2018 +0000 @@ -7,6 +7,7 @@ eth.init(ip,mask,gateway); eth.connect(); server.bind(4000); + server.listen(); server.set_blocking(false); for(int i=0;i<10;i++){ connections[i]=0; @@ -18,25 +19,30 @@ //Source:https://os.mbed.com/handbook/Socket bool incomingConnection=true; while(incomingConnection){ - TCPSocketConnection *connection=newConnection(); - if(server.accept(connection)==-1) - incomingConnection=false; + 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()); + } } - //client.set_blocking(false, 100); - - - printf("Connection from: %s\n", client.get_address()); - - } -void TCPlistener::receivePacket(char *contents,int 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); +bool TCPlistener::receiveSegment(char *contents,int size){ + for(int i=0;i<arraySize;i++){ + int n = connections[i]->receive(contents, size); + if(n!=-1){ + contents[n] = '\0'; + printf("Segment ontvangen van %s:%i met inhoud \"%s\"\r\n", connections[i]->get_address(),connections[i]->get_port(),contents); + return true; + } + } + return false; } -TCPSocketConnection * TCPlistener::newConnection(){ +TCPSocketConnection* TCPlistener::newConnection(){ bool searchLocation=true; for(int i=0;i<arraySize&&searchLocation;i++){ if(connections[i]==0){