Remote Procedure Call (RPC) over Websockets (uses MbedJSONValue)

Dependents:   RPC_mbed_client RPC_Wifly_HelloWorld RPC_Ethernet_HelloWorld

Revision:
7:067cb01b491e
Parent:
6:0ec91dd0e80e
--- a/MbedJSONRpc.h	Mon Oct 03 08:40:53 2011 +0000
+++ b/MbedJSONRpc.h	Thu Aug 23 14:23:37 2012 +0000
@@ -35,7 +35,6 @@
 #define _MbedJSONRPC_H_
 
 #include "Websocket.h"
-#include "Wifly.h"
 #include "mbed.h"
 #include "MbedJSONValue.h"
 #include <string>
@@ -98,154 +97,6 @@
 
 /** MbedJSONRpc class
  *
- * Warning: you must use a wifi module (Wifly RN131-C) or an ethernet network to use this class
- *
- * Example (client which registers one method):
- * @code
- * #include "mbed.h"
- * #include "MbedJSONRpc.h"
- * #include "MbedJSONValue.h"
- * #include "Websocket.h"
- *
- * #define WIFI
- *
- * #ifdef WIFI
- * #include "Wifly.h"
- * #endif
- *
- * DigitalOut led1(LED1);
- * Serial pc(USBTX, USBRX);
- *
- *
- * class Test {
- * public:
- *   Test() {};
- *   void fn(MbedJSONValue& val, MbedJSONValue& res) {
- *       printf("first arg: %s\r\n", val[0].get<string>().c_str());
- *       res[0] = "coucou";
- *       led1 = 1;
- *   }
- * };
- * 
- *
- * #ifdef WIFI
- * //wifi and websocket
- *  Wifly wifly(p9, p10, p30, "NETGEAR", "hello", true);
- *  Websocket webs("ws://sockets.mbed.org:888/ws/samux/server",&wifly);
- * #endif
- *
- * #ifdef ETHERNET
- *  Websocket webs("ws://sockets.mbed.org:888/ws/samux/server");
- * #endif
- *
- * //RPC object identified with the name "server" on the network and attached to the websocket server
- * MbedJSONRpc rpc(&webs);
- * 
- * Test test;
- *
- * int main() {
- *   
- *   RPC_TYPE t;
- *
- *
- *   //connection to the router and to the websocket server
- *   #ifdef WIFI
- *   while (1) {
- *
- *       while (!wifly.Join())  //we connect to the network
- *           wifly.reset();
- *
- *       if (!webs.connect())    //we connect to the server
- *           wifly.reset();
- *       else
- *           break;
- *   }
- *   #endif
- *  
- *   #ifdef ETHERNET
- *   while(!webs.connect())
- *       pc.printf("cannot connect websocket, retrying\r\n");
- *   #endif
- *
- *   //register the method Test::fn as "fn1"
- *   if((t = rpc.registerMethod("fn1", &test, &Test::fn)) == REGISTER_OK)
- *       printf("register ok\r\n");
- *   else
- *       printType(t);
- *   
- *   //Listen CALL requests
- *   rpc.work();
- * }
- * @endcode
- *
- *
- *
- * Example (client which calls the previous registered method):
- * @code
- * #include "mbed.h"
- * #include "MbedJSONRpc.h"
- * #include "MbedJSONValue.h"
- * #include "Websocket.h"
- *
- * #define ETHERNET
- *
- * #ifdef WIFI
- *   #include "Wifly.h"
- * #endif
- *
- * Serial pc(USBTX, USBRX);
- *
- * #ifdef WIFI
- *   //wifi and websocket
- *   Wifly wifly(p9, p10, p30, "NETGEAR", "hello", true);
- *   Websocket webs("ws://sockets.mbed.org:888/ws/samux/client",&wifly);
- * #endif
- *
- * #ifdef ETHERNET
- *   Websocket webs("ws://sockets.mbed.org:888/ws/samux/client");
- * #endif
- * 
- * //RPC object identified by the name "client" on the network and attached to the websocket server
- * MbedJSONRpc rpc(&webs);
- *
- * int main() {
- *
- *   //connection to the router and to the websocket server
- *   #ifdef WIFI
- *   while (1) {
- *
- *       while (!wifly.Join())  //we connect to the network
- *           wifly.reset();
- *
- *       if (!webs.connect())    //we connect to the server
- *           wifly.reset();
- *       else
- *           break;
- *   }
- *   #endif
- *  
- *   #ifdef ETHERNET
- *   while(!webs.connect())
- *       pc.printf("cannot connect websocket, retrying\r\n");
- *   #endif
- *   
- *   RPC_TYPE t;
- *   MbedJSONValue arg, resp;
- *   arg[0] = "Hello";
- *
- *   // print all methods and procedure available on the client "server"
- *   rpc.checkMethods("server");
- *       
- *   // Try to call the function "fn1" registered by server previously
- *   if((t = rpc.call("fn1", "server", arg, resp)) == CALL_OK)
- *   {
- *       printf("call success\r\n");
- *       printf("res: %s\r\n", resp[0].get<string>().c_str());
- *   }
- *   else
- *       printType(t);
- * }
- * @endcode
  */
 class MbedJSONRpc {
 public:
@@ -285,7 +136,7 @@
         MbedJSONValue tmp;
 
         sprintf(json, (const char *)MSG_REGISTER, my_id, id, public_name);
-        webs->Send(json);
+        webs->send(json);
         tmr.start();
         t = waitAnswer(tmp, id, json);
         if (t != REGISTER_OK)