本文整理汇总了C++中SocketHandler::Add方法的典型用法代码示例。如果您正苦于以下问题:C++ SocketHandler::Add方法的具体用法?C++ SocketHandler::Add怎么用?C++ SocketHandler::Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SocketHandler
的用法示例。
在下文中一共展示了SocketHandler::Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
try
{
SocketHandler h;
if (argc > 1 && !strcmp(argv[1], "-server"))
{
ListenSocket<tSocket> l(h);
l.Bind(4443);
h.Add(&l);
while (h.GetCount())
{
h.Select(1, 0);
}
}
else
{
std::string host = argc > 1 ? argv[1] : "www.alhem.net";
tSocket sock(h, host);
h.Add(&sock);
while (h.GetCount())
{
h.Select(1, 0);
}
}
}
catch (const Exception& e)
{
printf("%s\n", e.ToString().c_str());
}
}
示例2: main
int main(int argc, char *argv[])
{
SocketHandler h;
ListenSocket<IOSocket> l(h);
l.Bind(12344);
h.Add(&l);
IOSocket sock(h);
sock.Open("192.168.7.4", 12344);
h.Add(&sock);
while (!quit)
{
h.Select(1, 0);
}
}
示例3: main
int main(int argc, char *argv[])
{
int input,x;
SocketHandler h;
ListenSocket<DisplaySocket> l(h);
std::string text = argc > 1 ? argv[1] : "";
l.Bind(12346);
h.Add(&l);
pid_t pid = fork();
if (pid != 0) {
while (!done) {
x = scanf("%d",&input);
if (input == 1) {
done = 1;
kill(pid, SIGTERM);
}
}
} else {
while (1)
{
h.Select(1, 0);
printf("dada\n");
}
}
}
示例4: get_http
std::string get_http(const char *host, int port, const char *request)
{
SocketHandler h;
GetHttp sock(h, request);
sock.Open( host, port );
h.Add(&sock);
while (h.GetCount()) {
h.Select(1, 0);
}
return sock.Response();
}
示例5: main2
int main2()
{
SocketHandler h;
ListenSocket<ServerSocket> ll(h);
if (ll.Bind(443))
{
return -1;
}
h.Add(&ll);
h.Select(1,0);
while (h.GetCount())
{
h.Select(1,0);
}
}
示例6: main
int main()
{
SocketHandler h;
ListenSocket<ServerSocket> l(h);
if (l.Bind(40001,10))
{
exit(-1);
}
h.Add(&l);
h.Select(1,0);
while (h.GetCount())
{
h.Select(1,0);
}
}
示例7: SetSlaveHandler
void Socket::SocketThread::Run()
{
SocketHandler h;
h.SetSlave();
h.Add(m_socket);
m_socket -> SetSlaveHandler(&h);
m_socket -> OnDetached();
while (h.GetCount() && IsRunning())
{
h.Select(0, 500000);
}
// m_socket now deleted oops
// yeah oops m_socket delete its socket thread, that means this
// so Socket will no longer delete its socket thread, instead we do this:
SetDeleteOnExit();
}
示例8: main
int main(int argc,char *argv[])
{
if (argc > 1)
{
SocketHandler h;
ClientSocket cc(h,argv[1]);
cc.Open("127.0.0.1",40001);
// Add after Open
h.Add(&cc);
h.Select(1,0);
while (h.GetCount())
{
h.Select(1,0);
}
}
}
示例9: run
void run ()
{
SocketHandler h;
// Launch the RA listener socket
ListenSocket<RASocket> RAListenSocket (h);
bool usera = sConfig.GetBoolDefault ("Ra.Enable", false);
if (usera)
{
port_t raport = sConfig.GetIntDefault ("Ra.Port", 3443);
std::string stringip = sConfig.GetStringDefault ("Ra.IP", "0.0.0.0");
ipaddr_t raip;
if (!Utility::u2ip (stringip, raip))
sLog.outError ("MaNGOS RA can not bind to ip %s", stringip.c_str ());
else if (RAListenSocket.Bind (raip, raport))
sLog.outError ("MaNGOS RA can not bind to port %d on %s", raport, stringip.c_str ());
else
{
h.Add (&RAListenSocket);
sLog.outString ("Starting Remote access listner on port %d on %s", raport, stringip.c_str ());
}
}
// Socket Selet time is in microseconds , not miliseconds!!
uint32 socketSelecttime = sWorld.getConfig (CONFIG_SOCKET_SELECTTIME);
// if use ra spend time waiting for io, if not use ra ,just sleep
if (usera)
{
while (!World::IsStopped())
{
h.Select (0, socketSelecttime);
checkping ();
}
}
else
{
while (!World::IsStopped())
{
ACE_Based::Thread::Sleep(static_cast<unsigned long> (socketSelecttime / 1000));
checkping ();
}
}
}
示例10: main
int main(int argc, char *argv[])
{
std::string host = argc > 1 ? argv[1] : "www.alhem.net";
int port = argc > 2 ? atoi(argv[2]) : 80;
SocketHandler h;
for (int i = 1; i < 255; i++)
{
char host[40];
sprintf(host, "10.170.23.%d", i);
tSocket *p = new tSocket(h, host, 23);
h.Add(p);
}
while (h.GetCount())
{
h.Select(1, 0);
}
}
示例11: Run
void ResolvServer::Run()
{
// StdoutLog log;
SocketHandler h;
ListenSocket<ResolvSocket> l(h);
if (l.Bind("127.0.0.1", m_port))
{
return;
}
h.Add(&l);
m_ready = true;
while (!m_quit && IsRunning() )
{
h.Select(0, 500000);
}
SetRunning(false);
}
示例12: main
int main()
{
SocketHandler h;
ListenSocket<DisplaySocket> l(h);
StdoutLog log;
h.RegStdLog(&log);
if (l.Bind(9001))
{
exit(-1);
}
h.Add(&l);
h.Select(1,0);
while (!quit)
{
h.Select(1,0);
}
}
示例13: main
int main()
{
SocketHandler h;
StdoutLog log;
h.RegStdLog(&log);
ListenSocket<ServerSocket> l(h);
l.SetIpv6();
if (l.Bind(40001,10))
{
exit(-1);
}
h.Add(&l);
h.Select(1,0);
while (h.GetCount())
{
h.Select(1,0);
}
}
示例14: main
int main(int argc,char *argv[])
{
if (argc != 3)
{
fprintf(stderr, "Usage: %s <-hostname> <-port>\n", *argv);
exit(-1);
}
SocketHandler h;
MyClient sock(h);
port_t port = atoi(argv[2]);
if (port == 2222)
{
sock.EnableSSL();
}
sock.Open(argv[1], port);
h.Add(&sock);
while (h.GetCount())
{
h.Select();
}
}
示例15: main
int main(int argc,char *argv[])
{
if (argc < 2)
{
printf("Usage: %s <command>\n",*argv);
return -1;
}
SocketHandler h;
StdoutLog log;
h.RegStdLog(&log);
ClientSocket cc(h,argv[1]);
cc.SetIpv6();
cc.Open("localhost",40001);
// Add after Open
h.Add(&cc);
h.Select(1,0);
while (h.GetCount())
{
h.Select(1,0);
}
}