Home » U++ Library support » U++ MT-multithreading and servers » What's wrong with this code?
What's wrong with this code? [message #38215] |
Fri, 07 December 2012 04:01 |
lectus
Messages: 329 Registered: September 2006 Location: Brazil
|
Senior Member |
|
|
Why doesn't it compile?
#include "ServerTest.h"
void ServerTest::Accept(TcpSocket s)
{
s.Put("Hello world!\n");
}
void ServerTest::Serve() {
TcpSocket server;
if(!server.Listen(8080))
{
Exclamation("Error!");
return;
}
TcpSocket s;
s.Accept(server);
Thread().Run(callback1(Accept, s));
}
void ServerTest::BStartPush()
{
Thread().Run(callback(Serve));
}
ServerTest::ServerTest()
{
CtrlLayout(*this, "Window title");
bStart.WhenPush = THISBACK(BStartPush);
}
GUI_APP_MAIN
{
ServerTest().Run();
}
[Updated on: Fri, 07 December 2012 04:02] Report message to a moderator
|
|
|
Re: What's wrong with this code? [message #38217 is a reply to message #38215] |
Fri, 07 December 2012 06:01 |
nlneilson
Messages: 644 Registered: January 2010 Location: U.S. California. Mojave &...
|
Contributor |
|
|
In reference there are SocketClient and SocketServer
I started with those even though I had worked with socket server and clients in Python, Java and M$VC.
If you would zip your package (with the .upp file) it would be easier to try.
What are you doing for a client to test with?
What errors do you get?
[Updated on: Fri, 07 December 2012 06:05] Report message to a moderator
|
|
|
Re: What's wrong with this code? [message #38219 is a reply to message #38215] |
Fri, 07 December 2012 07:29 |
|
Hi lectus, I see couple problems
First you create the callbacks wrong. If you want to make callback to member function, you have to use the correct variant where you pass the object (you class) and fully qualified function name. The easiest way to do this is to use THISBACK* macros (requires "typedef ServerTest CLASSNAME;" in your class):
Thread().Run(THISBACK1(Accept, s));
Thread().Run(THISBACK(Serve)); ¨
Second thing that will not work is that you pass a socket as a parameter for the callback. TcpSocket has only private copy constructor, you you can't copy it into the callback so it can be used later. The socket should be member variable of your class, so you don't have to pass it around.
Also, Neil has a point about reading the manual and posting the complete compilable testcase. Or you should at least post the compiler messages if you want us to figure out why it won't compile, it is much easier then
Best regards,
Honza
|
|
|
Goto Forum:
Current Time: Fri Mar 29 12:21:38 CET 2024
Total time taken to generate the page: 0.01609 seconds
|