forked from sejinRyu/Chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.cpp
More file actions
101 lines (98 loc) · 2.11 KB
/
client.cpp
File metadata and controls
101 lines (98 loc) · 2.11 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "TcpSocket.h"
#include <string>
#include <vector>
using namespace std;
void login(ClientTcpSocket& client,string id,string pw)
{
client.send("0",23);
client.send(id,23);
client.send(pw,23);
cout<<client.receive(23)<<endl;
}
void adduser(ClientTcpSocket& client,string id,string pw,string name)
{
client.send("1",23);
client.send(id,23);
client.send(pw,23);
client.send(name,23);
cout<<client.receive(23)<<endl;
}
void deleteuser(ClientTcpSocket& client,string id,string pw)
{
client.send("2",23);
client.send(id,23);
client.send(pw,23);
cout<<client.receive(23)<<endl;
}
void addFriend(ClientTcpSocket& client,string name)
{
client.send("4",23);
client.send(name,23);
}
void printFriendList(ClientTcpSocket& client)
{
client.send("5",23);
while(1)
{
string tmp;
tmp=client.receive(23);
if(tmp=="end")
break;
cout<<tmp<<endl;
}
}
void deleteFriend(ClientTcpSocket& client,string name)
{
client.send("6",23);
client.send(name,23);
}
void makeChatRoom(ClientTcpSocket& client,string roomName,vector<string> invite)
{
client.send("7",23);
client.send(roomName,23);
for(string tmp:invite)
client.send(tmp,23);
client.send("end",23);
}
void echo(ClientTcpSocket& client)
{
client.send("9999",23);
pid_t pid=fork();
string tmp;
while(1)
{
if(pid>0)
{
tmp=client.receive(23);
cout<<tmp<<endl;
}
else
{
cin>>tmp;
client.send(tmp,23);
}
}
}
int main(int argc,char** argv)
{
try
{
ClientTcpSocket* client=new ClientTcpSocket;
login(*client,"a","b");
/*vector<string> a;
a.push_back("afwes");
a.push_back("shangus");
a.push_back("b");
makeChatRoom(*client,"ro1h",a);*/
//printFriendList(*client);
//addFriend(*client,"afwes");
//deleteuser(client,argv[1],argv[2]);
//echo(*client);
delete client;
}
catch(const char* e)
{
perror(e);
}
return 0;
}