oo-70-245-1

oo-70-245-1 Commit Details


Date:2014-10-25 14:24:23 (9 years 11 months ago)
Author:Natalie Adams
Branch:master
Commit:1dc40cb1ad5a50e77a0ba65aaa282ee5e0841a4c
Parents: c97d40505f9484f32c5f2e651b0fec4634b43aaf
Message:adding chatroom example

Changes:

File differences

Homework Examples/chatroom.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <ptypes.h>
#include <pasync.h>
#include <pinet.h>
USING_PTYPES;
tobjlist<ipstream> clients(false);
int i = 0;
class svthread: public thread
{
protected:
ipstream * c;
int i;
virtual void execute()
{
while(c->get_active())
{
try
{
string req = lowercase(c->line(4096));
req = "[" + itostring(i) + "] => " + req;
for(int i = 0; i < clients.get_count(); i++)
{
clients[i]->putline(req);
clients[i]->flush();
}
} catch (estream * e)
{
delete e;
break;
} catch (...) { }
}
for(int i = 0; i < clients.get_count(); i++)
{
if (clients[i] == c)
{
clients.del(i);
break;
}
}
delete c;
}
virtual void cleanup()
{
}
public:
svthread(ipstream * client, int ci): thread(false), c(client), i(ci) {}
virtual ~svthread() { }
};
int main()
{
tobjlist<thread> threads(true);
ipstmserver srv;
srv.bindall(245);
while(true)
{
ipstream * client = new ipstream();
srv.serve(*client);
svthread * t = new svthread(client, i);
threads.add(t);
t->start();
i++;
clients.add(client);
}
}

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.07140s using 14 queries.