-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.dart
72 lines (67 loc) · 1.78 KB
/
main.dart
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
// Sample code to send requests to Server
import 'dart:convert';
import 'dart:io';
void main() {
String host = 'localhost'; // Change to the actual host address
int port = 8080; // Change to the actual port number
void connectToServer() async {
Socket socket = await Socket.connect(host, port);
print('Connected to the server!');
socket.writeln('get_quotes');
String message = "";
await socket.listen(
(data) {
message = message + utf8.decode(data);
},
onDone: () {
print('Socket closed');
socket.destroy(); // Close the socket when the stream is done
},
);
}
void register() async {
Socket socket = await Socket.connect(host, port);
socket.writeln("sign_up");
socket.writeln("zulal");
socket.writeln("123123");
String message = "";
await socket.listen(
(data) {
message = message + utf8.decode(data);
},
onDone: () {
if (message.compareTo("StatusCode: 201") == 0) {
print("user is created");
} else {
print("user is not created");
}
print('Socket closed');
socket.destroy(); // Close the socket when the stream is done
},
);
}
void upvote_quote() async {
Socket socket = await Socket.connect(host, port);
socket.writeln("downvote_quote");
socket.writeln("4");
socket.writeln("3");
String message = "";
await socket.listen(
(data) {
message = message + utf8.decode(data);
},
onDone: () {
if (message.compareTo("StatusCode: 200") == 0) {
print("voted");
} else {
print("not voted");
}
print('Socket closed');
socket.destroy();
},
);
}
//connectToServer();
//register();
upvote_quote();
}