Hey Roberto,
2009/6/2 roberto <[email protected]>:
> I'm working with Fedora 10 and boost 1.34.1
> coming from the Fedora repo.
> wt is 2.2.4
> Which version of boost do you recommend?
I just tried our infamous WSocketNotifier with boost 1.34.1 and wt
2.2.4. This indeed seems to be broken. Boost asio's mechanism for
doing this changed in boost 1.36, and
It does work with later boost versions (I just tried wt 2.2.4 with
boost 1.36 and 1.37). I would therefore recommend 1.36 or later. :-)
See below a small (very silly) example that I use. It can only handle
a single session, and requires you to connect to port 7000 using
telnet after you started a session.
Regards,
koen
#include <Wt/WApplication>
#include <Wt/WContainerWidget>
#include <Wt/WText>
#include <Wt/WTimer>
#include <Wt/WSocketNotifier>
#include <iostream>
#include <arpa/inet.h>
#include <sys/socket.h>
using namespace Wt;
static int nextPort = 7000;
class TestApplication : public WApplication
{
public:
TestApplication(const WEnvironment& env);
private:
WSocketNotifier *notifier_;
WTimer *timer_;
void readSocket();
void update();
int socket_;
};
TestApplication::TestApplication(const WEnvironment& env)
: WApplication(env)
{
setTitle("Test Application");
int ssocket = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in address;
address.sin_family = AF_INET;
address.sin_addr.s_addr = INADDR_ANY;
std::cerr << "Please telnet to port " << nextPort << std::endl;
address.sin_port = htons(nextPort++);
socklen_t addrlen = sizeof(address);
bind(ssocket,(struct sockaddr *)&address, addrlen);
listen(ssocket, 3);
socket_ = accept(ssocket, (struct sockaddr *)&address, &addrlen);
/*
* Test WSocketNotifier
*/
notifier_ = new WSocketNotifier(socket_, WSocketNotifier::Read, this);
notifier_->activated.connect(SLOT(this, TestApplication::readSocket));
timer_ = new WTimer();
timer_->setInterval(500);
timer_->timeout.connect(SLOT(this, TestApplication::update));
timer_->start();
}
void TestApplication::readSocket()
{
char buf[100];
int s = read(socket_, buf, 99);
if (s == 0) {
notifier_->setEnabled(false);
close(socket_);
new WText("<b>Socket was closed.</b>", root());
delete timer_;
} else {
buf[s] = 0;
std::string s = buf;
new WText(s + "<br/>", root());
}
}
void TestApplication::update()
{ }
WApplication *createApplication(const WEnvironment& env)
{
return new TestApplication(env);
}
int main(int argc, char **argv)
{
return WRun(argc, argv, &createApplication);
}
------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises
looking to deploy the next generation of Solaris that includes the latest
innovations from Sun and the OpenSource community. Download a copy and
enjoy capabilities such as Networking, Storage and Virtualization.
Go to: http://p.sf.net/sfu/opensolaris-get
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest