demo versie 16/05
Dependencies: EthernetInterface mbed-rto mbed
Fork of ProjectVLC by
TCPlistener.cpp@50:c5cd73d93045, 2018-05-09 (annotated)
- Committer:
- KlaasGovaerts
- Date:
- Wed May 09 10:08:32 2018 +0000
- Revision:
- 50:c5cd73d93045
- Parent:
- 38:47c075a354b5
- Child:
- 62:237e32fd3555
Backup
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
KlaasGovaerts | 5:0413d42377d1 | 1 | #include "TCPlistener.h" |
KlaasGovaerts | 5:0413d42377d1 | 2 | |
KlaasGovaerts | 5:0413d42377d1 | 3 | TCPlistener::TCPlistener(){ |
KlaasGovaerts | 50:c5cd73d93045 | 4 | printf("creating TCPlistener\r\n"); |
albireo987 | 25:4c673da1a3ae | 5 | char ip[]="192.168.0.253"; |
albireo987 | 25:4c673da1a3ae | 6 | char mask[]="255.255.255.0"; |
KlaasGovaerts | 31:915f6cb7ffa5 | 7 | char gateway[]="192.168.0.254"; |
KlaasGovaerts | 5:0413d42377d1 | 8 | eth.init(ip,mask,gateway); |
KlaasGovaerts | 50:c5cd73d93045 | 9 | printf("Ethernet initialised.\r\n"); |
KlaasGovaerts | 5:0413d42377d1 | 10 | eth.connect(); |
KlaasGovaerts | 50:c5cd73d93045 | 11 | printf("connected to ethernet.\r\n"); |
KlaasGovaerts | 5:0413d42377d1 | 12 | server.bind(4000); |
KlaasGovaerts | 50:c5cd73d93045 | 13 | printf("Bound to port 4000.\r\n"); |
KlaasGovaerts | 16:ffd311730575 | 14 | server.listen(); |
KlaasGovaerts | 50:c5cd73d93045 | 15 | printf("Done listening.\r\n"); |
albireo987 | 38:47c075a354b5 | 16 | server.set_blocking(true); |
KlaasGovaerts | 15:5f1fda6b9140 | 17 | arraySize=10; |
KlaasGovaerts | 50:c5cd73d93045 | 18 | printf("TCPlistener created.\r\n"); |
KlaasGovaerts | 5:0413d42377d1 | 19 | } |
KlaasGovaerts | 13:f3db7045e220 | 20 | |
KlaasGovaerts | 16:ffd311730575 | 21 | bool TCPlistener::receiveSegment(char *contents,int size){ |
KlaasGovaerts | 20:4997b02d6a88 | 22 | printf("Maak een connectie.\r\n"); |
KlaasGovaerts | 20:4997b02d6a88 | 23 | TCPSocketConnection client; |
KlaasGovaerts | 20:4997b02d6a88 | 24 | server.accept(client); |
albireo987 | 32:537005b4a065 | 25 | int n=client.receive(contents,size); |
albireo987 | 38:47c075a354b5 | 26 | if(n!=-1){ |
albireo987 | 32:537005b4a065 | 27 | contents[n] = '\0'; |
albireo987 | 32:537005b4a065 | 28 | printf("Segment ontvangen van %s:%i met inhoud \"%s\"\r\n", client.get_address(),client.get_port(),contents); |
albireo987 | 32:537005b4a065 | 29 | return true; |
albireo987 | 32:537005b4a065 | 30 | } |
KlaasGovaerts | 16:ffd311730575 | 31 | return false; |
KlaasGovaerts | 19:5ee34e60a31d | 32 | } |