#include <iostream>
#include <Theron/Theron.h>
using namespace std;
struct HelloMessage {
char cstring[128];
};
class Actor : public Theron::Actor
{
public:
explicit Actor(Theron::Framework &framework) : Theron::Actor(framework)
{
RegisterHandler(this, &Actor::Handler1);
RegisterHandler(this, &Actor::Handler1);
}
private:
void DefaultHandler(const Theron::Address from)
{
cout<<"Actor received unknown message from address: "<< from.AsInteger();
}//接收到的消息地址
void Handler1(const HelloMessage &message, const Theron::Address from)
{
while (1){
cout << message.cstring <<"------";
cout << GetAddress().AsInteger()<<endl;//输出actor的地址
#ifdef SET_TIME
Sleep(1);
#else
Sleep(1000);
#endif
}
}
void Handler2(const HelloMessage &message, const Theron::Address from)
{
while (1){
cout << message.cstring << "------";
cout << GetAddress().AsInteger() << endl;//输出actor的地址
#ifdef SET_TIME
Sleep(1);
#else
Sleep(1000);
#endif
}
}
};
int main()
{
Theron::Receiver receiver;
Theron::Framework framework;
Actor actor1(framework);
Actor actor2(framework);
HelloMessage message;
strcpy_s(message.cstring, "Hello world!");
if (!framework.Send(message, actor2.GetAddress(), actor1.GetAddress())){
cout << "send message failed" << endl;
}
if (!framework.Send(message, actor1.GetAddress(), actor2.GetAddress())){
cout << "send message failed" << endl;
}
receiver.Wait();
system("PAUSE");
return 0;
}
#include <Theron/Theron.h>
using namespace std;
struct HelloMessage {
char cstring[128];
};
class Actor : public Theron::Actor
{
public:
explicit Actor(Theron::Framework &framework) : Theron::Actor(framework)
{
RegisterHandler(this, &Actor::Handler1);
RegisterHandler(this, &Actor::Handler1);
}
private:
void DefaultHandler(const Theron::Address from)
{
cout<<"Actor received unknown message from address: "<< from.AsInteger();
}//接收到的消息地址
void Handler1(const HelloMessage &message, const Theron::Address from)
{
while (1){
cout << message.cstring <<"------";
cout << GetAddress().AsInteger()<<endl;//输出actor的地址
#ifdef SET_TIME
Sleep(1);
#else
Sleep(1000);
#endif
}
}
void Handler2(const HelloMessage &message, const Theron::Address from)
{
while (1){
cout << message.cstring << "------";
cout << GetAddress().AsInteger() << endl;//输出actor的地址
#ifdef SET_TIME
Sleep(1);
#else
Sleep(1000);
#endif
}
}
};
int main()
{
Theron::Receiver receiver;
Theron::Framework framework;
Actor actor1(framework);
Actor actor2(framework);
HelloMessage message;
strcpy_s(message.cstring, "Hello world!");
if (!framework.Send(message, actor2.GetAddress(), actor1.GetAddress())){
cout << "send message failed" << endl;
}
if (!framework.Send(message, actor1.GetAddress(), actor2.GetAddress())){
cout << "send message failed" << endl;
}
receiver.Wait();
system("PAUSE");
return 0;
}