Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years, 6 months ago.
EthernetNetIf TCP Socket connection problem
in my programm i try to connect to a server with the TCPSocket class from the EthernetNetIf lib, but I just get the error that
"expression must have class type" in file "/HTTPServer.cpp", Line: 55, Col: 4
But what am I doing wrong I tried anything with const, pointers etc. I read the api carefully please help me to solve my problem.
Here is the code:
include the mbed library with this snippet
#include "mbed.h" #include "EthernetNetIf.h" #include "HTTPServer.h" #include "RPCFunction.h" /* * global Variables */ EthernetNetIf eth( IpAddr(192,168,1,22), IpAddr(255,255,255,0), IpAddr(192,168,0,1), IpAddr(192,168,0,1) ); HTTPServer svr; LocalFileSystem fs("webfs"); Serial pc(USBTX, USBRX); TCPSocket *socket(); Host nodeServer(); /* * RPC functions */ void foo(char * input, char * output); RPCFunction rpcFoo(&foo, "foo"); int main() { /* * Ethernet Inferface */ printf("Setting up...\r\n"); EthernetErr ethErr = eth.setup(); if (ethErr) { printf("Error %d in setup.\r\n", ethErr); return -1; } printf("Setup OK\r\n"); /* * HTTP Server */ FSHandler::mount("/webfs", "/"); //Mount /webfs path on web root path svr.addHandler<SimpleHandler>("/hello"); //Default handler svr.addHandler<RPCHandler>("/rpc"); svr.addHandler<FSHandler>("/"); //Default handler svr.bind(80); printf("Listening...\r\n"); /* * TCP Socket */ IpAddr nodeIp(192,168,1,22); Host node(nodeIp, 2222, ""); socket.connect(&node); /* * Endless loop */ while (true) { Net::poll(); } } /* * Functions */ void foo(char * input, char * output) { pc.printf("foo\n"); }
3 Answers
11 years, 6 months ago.
I have never used the ethernet myself, however from a pure syntax perspective: Either line 55 must use a -> instead of a '.', Or on line 18 it must be declared without the '*'. (That last one probably).
11 years, 6 months ago.
Thank you but none of this was working. I also tried to import some other lib the EthernetInfterface library that is surely working but when i import it i just get errors. why is that?
11 years, 3 months ago.
Hmm, I have got the same error in my fresh own class. Example:
DCM mydcm(void); mydcm.doSome(); // raise error
But my old class works fine:
ESC esc(p21,p22,p23,p24); esc.init(); // all is ok
Looks like an error in mbed compiler :(
I seriously doubt it is an error in the compiler. What it is is hard to tell without more info. Generally it happens when you use '.' to call a function while you have a pointer to a class. That isn't the case in your two lines, but surely there are more lines of relevant code.
posted by 07 Aug 2013Are you sure that this isn't the case in those two lines which fail?
DCM mydcm(void);
That looks like it might be a prototype for a function which takes no parameters and returns an object of type DCM. I don't think is instantiating an object of type DCM.
posted by 07 Aug 2013I think, I have found the solution. When we write class contructor without arguments, like:
class MYC{ public: int x; MYC(void); }; MYC::MYC(void){ }
And then try to get some methods or properties from object:
#include "mbed.h" #include "MYC.h" MYC myc(); int main() { float x; x = myc.x; }
so we get the error.
But, when we set some arguments in constructor, even unuseful:
class MYC{ public: int x; MYC(int x); }; MYC::MYC(int xx){ x = xx; }
#include "mbed.h" #include "MYC.h" MYC myc(1); int main() { int x; x = myc.x; }
All is ok
posted by 07 Aug 2013For your first example:
MYC myc();
You do this instead:
MYC myc;
Just drop the parens.
posted by 07 Aug 2013