Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
ftserver.h
00001 #ifndef FTSERVER_H 00002 #define FTSERVER_H 00003 #include <list> 00004 using namespace std; 00005 00006 void handleMessage(char[7]); 00007 class connection; 00008 00009 class ftServer { 00010 list<connection*> queue; 00011 TCPSocket listeningSock; 00012 TCPSocketErr err; 00013 char msg[7]; 00014 char *text; 00015 char textlen, index; 00016 bool isMsg; 00017 protected: 00018 void onTCPEvent(TCPSocketEvent ev); 00019 char* render(); 00020 public: 00021 ftServer(IpAddr host, unsigned short port); 00022 bool startServer(); 00023 // void pollServer(); 00024 void errorMsg(); 00025 bool readStream(TCPSocket *pConnectedSock); 00026 bool writeStream(char *); 00027 bool writeStream(SMESSAGE*); 00028 void remove(connection* c); 00029 void handleMessage() { 00030 ::handleMessage(msg); //change this to a function pointer 00031 } 00032 int clients() { return queue.size();} 00033 }; 00034 00035 class connection { 00036 TCPSocket * pConnectedSock; 00037 Host client; 00038 ftServer *server; 00039 void onConnectedTCPSocketEvent(TCPSocketEvent ev); 00040 public: 00041 connection(ftServer *svr, Host h, TCPSocket *s): server(svr), client(h), pConnectedSock(s) { 00042 pConnectedSock->setOnEvent(this, &connection::onConnectedTCPSocketEvent); //Setup the new socket events 00043 char str[80]; 00044 sprintf(str, "Message from Server: Connection OK. Client nr %d", server->clients()); 00045 writeStream(str); 00046 //should also send the present state of the inputs, ne clean way to access the ft-interface 00047 } 00048 ~connection() { 00049 pConnectedSock->close();//close and destroy the socket created by 'accept' 00050 } 00051 bool writeStream(char *); 00052 bool writeStream(SMESSAGE*); 00053 const TCPSocket* socket() const { 00054 return pConnectedSock; 00055 } 00056 }; 00057 00058 #endif
Generated on Tue Jul 12 2022 20:02:50 by
1.7.2