11 class TUserHandler :
public THttpWSHandler {
16 TUserHandler(
const char *name = 0,
const char *title = 0) : THttpWSHandler(name, title), fWSId(0), fServCnt(0) {}
19 TString GetDefaultPageContent() {
return "file:ws.htm"; }
21 virtual Bool_t ProcessWS(THttpCallArg *arg)
23 if (!arg || (arg->GetWSId()==0))
return kTRUE;
27 if (arg->IsMethod(
"WS_CONNECT")) {
32 if (arg->IsMethod(
"WS_READY")) {
33 fWSId = arg->GetWSId();
34 printf(
"Client connected %d\n", fWSId);
38 if (arg->IsMethod(
"WS_CLOSE")) {
40 printf(
"Client disconnected\n");
44 if (arg->IsMethod(
"WS_DATA")) {
46 str.Append((
const char *)arg->GetPostData(), arg->GetPostDataLength());
47 printf(
"Client msg: %s\n", str.Data());
49 SendCharStarWS(arg->GetWSId(), Form(
"Server replies:%s server counter:%d", now.AsString(), fServCnt++));
57 virtual Bool_t HandleTimer(TTimer *)
60 if (fWSId) SendCharStarWS(fWSId, Form(
"Server sends data:%s server counter:%d", now.AsString(), fServCnt++));
68 THttpServer *serv =
new THttpServer(
"http:8090");
70 TUserHandler *handler =
new TUserHandler(
"name1",
"title1");
72 serv->Register(
"/folder1", handler);
74 const char *addr =
"http://localhost:8090/folder1/name1/";
76 printf(
"Starting browser with URL address %s\n", addr);
77 printf(
"In browser content of ws.htm file should be loaded\n");
79 if (gSystem->InheritsFrom(
"TMacOSXSystem"))
80 gSystem->Exec(Form(
"open %s", addr));
82 gSystem->Exec(Form(
"xdg-open %s &", addr));
85 TTimer *tm =
new TTimer(handler, 3700);