-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtcpClient.html
250 lines (248 loc) · 9.95 KB
/
tcpClient.html
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TCP Client</title>
<style>
*{margin:0; padding:0; font-family:Microsoft YaHei, Arial, Helvetica, sans-serif; color:#FFFFFF; font-size:15px;}
body{background-color:#000; display:none}
div{overflow:hidden; box-sizing:border-box;}
#app{width:100%; height:100vh; max-width:1200px; margin:0 auto;}
.flex{display:flex;}
.rows, .row{flex-direction:row !important;}
.columns, .column{flex-direction:column !important;}
.wrap{flex-direction:row !important; flex-wrap:wrap !important;}
.nowrap{flex-direction:row !important; flex-wrap:nowrap !important;}
.space-around{justify-content:space-around !important;}
.space-between{justify-content:space-between !important;}
.justify-content-start{justify-content:flex-start !important;}
.justify-content-center{justify-content:center !important;}
.justify-content-end{justify-content:flex-end !important;}
.align-items-start{align-items:flex-start !important;}
.align-items-center{align-items:center !important;}
.align-items-end{align-items:flex-end !important;}
.flex1{flex:1 !important;}
#left{width:30%; background:#1D1D1D; height:100vh; padding:20px; display:flex; flex-direction: column;}
#left > ul{flex:1; margin-top:20px; overflow-y: auto;}
#center{width:50%; margin-left:20px; background-color:#212332; flex:1; height:100vh; padding:20px;}
.h3{font-size:18px; font-weight:bold; line-height:20px;}
.input {display: block; width:200px; padding: 0.5rem 1rem; font-weight: 400; line-height: 1.3;
background-color: #2A2D3E;
background-clip: padding-box;
border:none;
appearance: none;
border-radius:5px;
outline: none;
box-sizing: border-box;
resize: none;
}
.button {
display: flex !important;
flex-direction: row;
justify-content: center;
align-items: center;
padding: 0.5rem 20px;
background:#2697FF;
border:none;
border-radius:5px;
cursor: pointer;
}
.button:active{
background-color:#0679cc;
}
ul li{list-style:none;}
.server-item{background-color:#333333; line-height:1.5em; padding:10px; border-radius:3px; margin-bottom:15px;}
.server-item .title{font-size:15px;}
.server-item .desc{font-size:13px; margin-top:5px;}
.quick-message{font-size:13px;}
.quick-message span{cursor: pointer; font-size:13px;}
.item-small-space{padding:6px;}
.blue{color:#3688FF;}
.font12{font-size:12px;}
.consumer{padding-left:20px; font-size:12px;}
.cursor{cursor: pointer;}
::-webkit-scrollbar {width:5px; height:10px; background-color:#F5F5F5;}
::-webkit-scrollbar-track{-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); background-color: #0679cc;}
::-webkit-scrollbar-thumb{-webkit-box-shadow: inset 0 0 5px rgba(0,0,0,.3); background-color: #555555;}
</style>
</head>
<body>
<div id="app" class="flex row space-between">
<div id="left">
<div class="flex row space-between" style="width:100%;">
<h3 class="h3">集群节点</h3>
<span class="cursor font12" @click="getServerStatus">刷新</span>
</div>
<ul v-if="serverList != null">
<li v-for="(item, k) in serverList" :key="k" class="server-item">
<div class="title blue">{{k}}</div>
<div class="title" style="margin-top:8px;">话题列表</div>
<ul style="margin-top:5px;">
<li class="item-small-space" v-for="(topic, topicIndex) in item">
<div>▤ {{topicIndex}} <span class="font12">( {{topic.saveIndex}} )</span></div>
<ul>
<li class="consumer" v-for="(consumer, consumerIndex) in topic.consumerGroups">
|_ {{consumer.Name}} : {{consumer.ConsumeIndex}}/{{consumer.FillIndex}}
</li>
</ul>
</li>
</ul>
</li>
</ul>
<div style="height:10px;"></div>
</div>
<div id="center">
<div class="title">连接信息</div>
<div class="flex row space-between" style="margin-top:15px;">
<input
type="text" class="input flex1" v-model="serverAddr" />
<button
type="button" class="button" style="margin-left:15px;"
@click="connect">连接</button>
</div>
<div class="title" style="margin-top:25px;">响应结果</div>
<div style="margin-top:15px;">
<textarea class="input" id="result" v-model="responseMessage" style="height:288px; width:100%; scroll-margin-top:900px;"></textarea>
</div>
<div class="title" style="margin-top:25px;">发送消息</div>
<div style="margin-top:15px;">
<textarea class="input" v-model="defaultMessage" style="height:88px; width:100%;"></textarea>
</div>
<div class="flex row space-between" style="margin-top:12px;">
<div class="quick-message flex1">
快捷命令 :
<span @click="quickMessage(1)">生产</span>
·
<span @click="quickMessage(2)">消费</span>
·
<span @click="quickMessage(3)">创建话题</span>
·
<span @click="quickMessage(7)">创建消费者组</span>
</div>
<button class="button" @click="submitMessage">发送</button>
</div>
</div>
</div>
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery/1.7.2/jquery.min.js"></script>
<script src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/vue/3.2.31/vue.global.min.js"></script>
<script>
const { createApp, ref } = Vue;
createApp({
data:function(){
return {
serverAddr : "192.168.31.188:8883",
responseMessage : "",
socket : null,
serverList : null,
defaultMessage : "",
pool : null,
}
},
mounted:function(){},
methods:{
connect:function(){
if(this.socket != null){
this.responseMessage += "… 当前连接关闭中 ...\n";
this.socket.close();
this.socket = null;
return ;
}
this.responseMessage += "… " + this.serverAddr+" 连接中 ...\n";
this.socket = new WebSocket('ws://'+this.serverAddr);
this.socket.onopen = ()=>{
this.responseMessage += "✔ " + this.serverAddr+" 连接成功\n";
// 查询服务器列表
this.getServerStatus();
};
this.socket.onclose = ()=>{
this.responseMessage += "✘ " + this.serverAddr+" 连接断开\n";
this.socket = null;
setTimeout(()=>{
this.connect();
},2000);
};
this.socket.onmessage = (event)=>{
var message = event.data;
var messageObj = JSON.parse(message);
if(messageObj.ErrCode != 0){
this.responseMessage += "✘ " + messageObj.Data + "\n";
return ;
}
switch(messageObj.Type){
case 1:
this.responseMessage += "✔ " + messageObj.Data + "\n";
setTimeout(()=>{
this.getServerStatus();
}, 2000);
break
case 2:
this.responseMessage += "✔ 消费成功,消息内容 : " + messageObj.Data + "\n";
this.getServerStatus();
break
case 3:
this.responseMessage += "✔ 话题创建成功 : " + messageObj.Data + "\n";
this.getServerStatus();
break
case 7:
this.responseMessage += "✔ 消费者组创建成功 : " + messageObj.Data + "\n";
this.getServerStatus();
break
case 11:
var dataNew = JSON.parse(messageObj.Data);
this.serverList = dataNew;
default:
}
};
this.socket.onerror = (error)=>{
this.responseMessage += "✘ " + this.serverAddr+" 连接失败\n";
this.socket = null;
};
},
getServerStatus:function(){
this.sendMessage({Action:11});
},
sendMessage:function(msg){
if(typeof msg != "string"){
msg = JSON.stringify(msg);
}
if(this.socket != null){
this.socket.send(msg);
}else{
this.responseMessage += "☹ 请先连接服务器\n";
}
},
submitMessage : function(){
this.sendMessage(this.defaultMessage);
this.defaultMessage = "";
},
quickMessage : function(tp){
switch(tp){
case 1:
this.defaultMessage = '{"Action":1, "Topic":"default", "Data":"hello world"}';
break;
case 2:
this.defaultMessage = '{"Action":2, "Topic":"default", "ConsumerGroup":"default"}';
break;
case 3:
this.defaultMessage = '{"Action":3, "Topic":"default"}';
break;
case 7:
this.defaultMessage = '{"Action":7, "Topic":"default", "ConsumerGroup":"consumer01"}';
break;
}
}
},
watch:{
responseMessage : function(newVal, oldVal){
textArea = document.getElementById('result');
textArea.scrollTop = textArea.scrollHeight + 100;
}
}
}).mount('#app');
$(function(){
$('body').fadeIn(200);
});
</script>
</body>
</html>