WIZ820io(W5200) network interface、EthernetNetIf compatible.
example
#include "WIZ820ioNetIf.h" #include "HTTPClient.h" #include "HTTPServer.h" #if defined(TARGET_KL25Z) WIZ820ioNetIf eth(PTD2,PTD3,PTD1,PTD0,PTD5); #endif HTTPClient http; HTTPStream stream; void callback(HTTPResult r){ printf("callback %d %s\n", r, HTTPClient::ResultStr(r)); } int main() { int err = eth.setup(); if (err < 0) { printf("setup error %d\n", err); exit(-1); } HTTPServer svr; svr.addHandler<SimpleHandler>("/"); svr.bind(80); const char* uri = "http://va009039-mbed.appspot.com/kl25z/"; http.get(uri, &stream, callback); uint8_t buf[256]; int total = 0; stream.readNext(buf, sizeof(buf)); while(1) { if(stream.readable()) { int len = stream.readLen(); total += len; printf("%d %d\n", total, len); stream.readNext(buf, sizeof(buf)); } Net::poll(); } }
MyNetTcpSocket.h@1:22b9052d864d, 2013-03-24 (annotated)
- Committer:
- va009039
- Date:
- Sun Mar 24 11:25:31 2013 +0000
- Revision:
- 1:22b9052d864d
- Parent:
- 0:bdeec5f86894
WIZ820io(W8200) ethernet interface, EthernetNetIf compatible.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 0:bdeec5f86894 | 1 | // MyNetTcpSocket.h 2012/4/16 |
va009039 | 0:bdeec5f86894 | 2 | #ifndef MYNETTCPSOCKET_H |
va009039 | 0:bdeec5f86894 | 3 | #define MYNETTCPSOCKET_H |
va009039 | 0:bdeec5f86894 | 4 | #include "if/net/nettcpsocket.h" |
va009039 | 0:bdeec5f86894 | 5 | |
va009039 | 0:bdeec5f86894 | 6 | class MyNetTcpSocket : public NetTcpSocket { |
va009039 | 0:bdeec5f86894 | 7 | public: |
va009039 | 0:bdeec5f86894 | 8 | MyNetTcpSocket(int socket = (-1)); |
va009039 | 0:bdeec5f86894 | 9 | virtual ~MyNetTcpSocket(); |
va009039 | 0:bdeec5f86894 | 10 | virtual NetTcpSocketErr bind(const Host& me); |
va009039 | 0:bdeec5f86894 | 11 | virtual NetTcpSocketErr listen(); |
va009039 | 0:bdeec5f86894 | 12 | virtual NetTcpSocketErr connect(const Host& host); |
va009039 | 0:bdeec5f86894 | 13 | virtual NetTcpSocketErr accept(Host* pClient, NetTcpSocket** ppNewNetTcpSocket); |
va009039 | 0:bdeec5f86894 | 14 | virtual int /*if < 0 : NetTcpSocketErr*/ send(const char* buf, int len); |
va009039 | 0:bdeec5f86894 | 15 | virtual int /*if < 0 : NetTcpSocketErr*/ recv(char* buf, int len); |
va009039 | 0:bdeec5f86894 | 16 | virtual NetTcpSocketErr close(); |
va009039 | 0:bdeec5f86894 | 17 | virtual NetTcpSocketErr poll(); |
va009039 | 0:bdeec5f86894 | 18 | protected: |
va009039 | 0:bdeec5f86894 | 19 | int _socket; |
va009039 | 0:bdeec5f86894 | 20 | bool wait_accept; |
va009039 | 0:bdeec5f86894 | 21 | private: |
va009039 | 0:bdeec5f86894 | 22 | void cleanUp(); //Flush input buffer |
va009039 | 0:bdeec5f86894 | 23 | queue<MyNetTcpSocket*> m_lpInNetTcpSocket; |
va009039 | 0:bdeec5f86894 | 24 | }; |
va009039 | 0:bdeec5f86894 | 25 | #endif //MYNETTCPSOCKET_H |