forked from alajia626/aardio-FTPServer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasynFtpServer.aardio
657 lines (595 loc) · 21.3 KB
/
asynFtpServer.aardio
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
//asynFtpServer 异步FTP服务端
import wsock.tcp.server;
import wsock.tcp.asynServer;
import fsys;
import fsys.file;
import console;
import fsys.codepage;
class asynFtpServer{
ctor(documentRoot,fdPort){
var errMsg;
this,errMsg = ..wsock.tcp.asynServer();
if(!this) return null,errMsg;
this.maxConnection = 500;
this.keepAliveTimeout = 120;
this.documentRoot = documentRoot : "/";
this.localPort = fdPort:21;
this.conn_list = {};
this.myIp = function(){
import com;
var strComputer = "."
var objWMIService = ..com.GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" + strComputer + "\root\cimv2")
var colItems = objWMIService.ExecQuery("select * from Win32_NetworkAdapterConfiguration where IPEnabled=true",null,48)
var OS = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
if(colItems){
for index, item in com.each(colItems) {
if(..string.startWith(item.IPAddress(0),"192.168.")){
return item.IPAddress(0);
}
}
}
}
this.localIp = this.myIp();
this.requestInfo = function(hSocket,arg){
var arg = arg;
if(!..fsys.codepage.isTextUtf8(arg)){
arg = ..string.fromto(arg,0,65001)
}
this.conn_list[hSocket].request_info = {};
var tmpStr;
if(arg[[1]] = "\" or arg[[1]] = '/'){
tmpStr = arg;
}
else {
tmpStr = ..io.joinpath(this.conn_list[hSocket].curr_dir,arg);
}
if(..fsys.isDir(tmpStr)){
this.conn_list[hSocket].request_info.isDir = true;
if(!..string.endWith(tmpStr,"\\")){
tmpStr ++= "\"
}
}
else {
this.conn_list[hSocket].request_info.isDir = false;
this.conn_list[hSocket].request_info.fileName = ..io.splitpath(tmpStr).file;
tmpStr = ..io.splitpath(tmpStr).dir;
}
var dir = ..string.replace(tmpStr,"\\","/");
var xdir = ..string.split(dir,'/');
var correct = true; //路径正确性验证
for(k,v in xdir){
if(v=="."){
continue;
}
elseif(v==".."){
if(k>1){
var flag = 0;
for(j=k-1;1;-1){
if(#xdir[j]){
xdir[j] = "";
flag = 1;
break;
}
}
if(!flag){
correct = false;
break;
}
}
else {
correct = false;
break;
}
}
else {
}
}
if(!correct){
return ;
}
var newPath = "/";
for(k,v in xdir){
if(#v and v != ".." and v != "."){
newPath ++= v + "/"
}
}
this.conn_list[hSocket].request_info.newPath = newPath;
var realPath = ..io.joinpath(this.documentRoot,newPath);
this.conn_list[hSocket].request_info.realPath = realPath;
this.conn_list[hSocket].request_info.existPath = false;
this.conn_list[hSocket].request_info.existFile = false;
if(..io.exist(realPath)){
this.conn_list[hSocket].request_info.existPath = 1;
if(!this.conn_list[hSocket].request_info.isDir){
var fpath = this.conn_list[hSocket].request_info.realPath ++ this.conn_list[hSocket].request_info.fileName;
if(..io.exist(fpath)){
this.conn_list[hSocket].request_info.existFile = 1;
}
}
}
this.conn_list[hSocket].request_info.canRead = true;
this.conn_list[hSocket].request_info.canWrite = true;
this.conn_list[hSocket].request_info.canModify = true;
if(type(this.permission)==type.function){
var userId = this.conn_list[hSocket].userId;
var read,write,modify = this.permission(userId,newPath);
this.conn_list[hSocket].request_info.canRead = read;
this.conn_list[hSocket].request_info.canWrite = write;
this.conn_list[hSocket].request_info.canModify = modify;
}
return true;
}
this._beforeStop = function(){
if( this._beforeFtpServerStop ) this._beforeFtpServerStop();
}
this.onOpen = function(hSocket,err){
var client = this.client(hSocket);
if(this.acceptCount < this.maxConnection){
this.conn_list[hSocket] = {};
this.conn_list[hSocket].fd = client;
this.conn_list[hSocket].data_fd = 0;
this.conn_list[hSocket].option_pasv = false;
this.conn_list[hSocket].option_utf8 = true;
this.conn_list[hSocket].userId = "";
this.conn_list[hSocket].curr_dir = "/";
this.conn_list[hSocket].type = "A";
return client.send("220 Welcome!FTP Utility server (Version 1.00) is ready." + '\r\n');
}
else {
client.send("500 Too many connections!" + '\r\n');
return client.close();
}
}
this.onRead = function(hSocket,err){
var client = this.client(hSocket);
var data = client.readAll();
if(!..string.endWith(data,'\r\n',true)){
return client.send("550 failed.");
}
var cmdLine = "";
var arg = "";
var space = ..string.indexOf(data," ");
if(space){
cmdLine = ..string.upper(..string.left(data,space-1));
arg = ..string.slice(data,space+1,-3);
}
else {
cmdLine = ..string.slice(data,1,-3);
}
if(cmdLine == "BYE" or cmdLine == "QUIT"){
this.conn_list[hSocket] = null;
return client.send("221 Goodbye. " + '\r\n');
}
elseif(cmdLine == "USER"){
if(arg == ""){
return client.send("530 Please Login with USER and PASS." + '\r\n');
}
else {
if(type(this.identify)==type.function){
this.conn_list[hSocket].loginName = arg;
return client.send("331 Password required for " + arg + '\r\n');
}
else {
this.conn_list[hSocket].userId = arg;
return client.send("230 Login successful." + '\r\n');
}
}
}
elseif(cmdLine == "PASS"){
if(arg == "" or !this.conn_list[hSocket].loginName){
return client.send("530 Please Login with USER and PASS." + '\r\n');
}
elseif(type(this.identify)==type.function){
var userId = this.conn_list[hSocket].loginName;
result = this.identify(userId, arg);
if(result){
this.conn_list[hSocket].loginName = null;
this.conn_list[hSocket].userId = userId;
return client.send("230 Login successful." + '\r\n');
}
else {
return client.send("550 failed." + '\r\n');
}
}
}
elseif(this.conn_list[hSocket].userId == ""){
return client.send("530 Please Login with USER and PASS." + '\r\n');
}
if(cmdLine == "NOOP"){
return client.send("200 Command okay." + '\r\n')
}
elseif(cmdLine == "TYPE"){
if(arg =="ASCII"){
this.conn_list[hSocket].type = "A";
}
elseif(arg =="binary"){
this.conn_list[hSocket].type = "I";
}
return client.send("200 Command okay." + '\r\n')
}
elseif(cmdLine == "SYST"){
return client.send("200 WINDOWS" + '\r\n')
}
elseif(cmdLine == "EPSV" or cmdLine == "PASV"){
var dataSocket = ..wsock.tcp.server(this.localIp,0,1);
var ip,port = dataSocket.getLocalIp();
this.conn_list[hSocket].data_fd = dataSocket.hSocket;
var str = "";
if cmdLine == "EPSV"{
str = "229 Entering Extended Passive Mode (|||" ++ tostring(port) ++ "|)"
}
else{
var m = ..math.floor(port/256)
var n = port%256
str = ..string.replace(this.localIp,'@.',",");
str = str ++ "," ++ tostring(m) ++"," ++ tostring(n);
str = "227 Entering Passive Mode (" + str + ").";
}
this.conn_list[hSocket].option_pasv = true;
return client.send(str + '\r\n');;
}
elseif(cmdLine == "EPRT"){
return client.send("500 implement EPRT later..." + '\r\n')
}
elseif(cmdLine == "PORT"){
if(arg==""){
return client.send("500 Failed." + '\r\n');
}
var arg = ..string.split(..string.trim(arg),",");
if(#arg!=6){
return client.send("500 Failed." + '\r\n');
}
var port = 256*tonumber(arg[5]) + tonumber(arg[6]);
this.conn_list[hSocket].data_ip = ..string.join(arg,".",1,4);
this.conn_list[hSocket].data_port = port;
if(this.conn_list[hSocket].data_fd){
..wsock.closesocket(this.conn_list[hSocket].data_fd);
this.conn_list[hSocket].data_fd = 0;
}
this.conn_list[hSocket].option_pasv = false;
return client.send("200 PORT Command okay." + '\r\n')
}
elseif(cmdLine == "PWD" or cmdLine == "XPWD"){
return client.send("257 " ++ '"' + this.conn_list[hSocket].curr_dir ++ '"\r\n');
}
elseif(cmdLine == "LIST" or cmdLine == "NLST"){
var path = arg:"";
if(!this.requestInfo(hSocket,path) or !this.conn_list[hSocket].request_info.existPath){
return client.send("500 Failed." + '\r\n');
}
if(!this.conn_list[hSocket].request_info.canRead){
return client.send("550 Permission denied." + '\r\n');
}
var socket;
if(this.conn_list[hSocket].option_pasv){
if(this.conn_list[hSocket].data_fd == 0){
return client.send("425 Can't open data connection." + '\r\n')
}
acceptSocket = ..wsock.accept(this.conn_list[hSocket].data_fd);
if( acceptSocket == _INVALID_SOCKET ){
return client.send("425 Can't open data connection." + '\r\n')
}
socket = ..wsock.tcp.client(,acceptSocket);
}
else {
if(!this.conn_list[hSocket].data_ip or !this.conn_list[hSocket].data_port){
return client.send("500 Failed." + '\r\n');
}
socket = ..wsock.tcp.client();
if( !socket.connect(this.conn_list[hSocket].data_ip,this.conn_list[hSocket].data_port) ){
return client.send("425 Can't open data connection." + '\r\n')
}
}
client.send("150 Opening ASCII mode data connection for file list. " + '\r\n');
var info = "";
var file,dir = ..fsys.list(this.conn_list[hSocket].request_info.realPath,,"*.*");
for(i=1;#dir;1){
info += 'folder: ' + dir[i] + '\r\n';
}
for(i=1;#file;1){
info += 'file: ' + file[i] + '\r\n';
}
if(!this.conn_list[hSocket].option_utf8){
info = ..string.fromto(info);
}
socket.send(info,#info);
socket.close();
this.conn_list[hSocket].data_fd = 0;
return client.send("226 Transfer complete." + '\r\n');
}
elseif(cmdLine == "REST"){
this.conn_list[hSocket].file_pos = int(arg);
return client.send("250 OK" + '\r\n');
}
elseif(cmdLine == "FEAT"){
var features = `211-Features:\r\nSITES\r\nEPRT\r\nEPSV\r\nMDTM\r\nPASV\r\nREST STREAM\r\nSIZE\r\nUTF8\r\n211 End\r\n`
return client.send(features + '\r\n');
}
elseif(cmdLine == "OPTS"){
arg = ..string.upper(arg)
if(arg == "UTF8 ON"){
this.conn_list[hSocket].option_utf8 = true
return client.send("200 Command okay." + '\r\n')
}
elseif(arg == "UTF8 OFF"){
this.conn_list[hSocket].option_utf8 = false
return client.send("200 Command okay." + '\r\n')
}
else{
return client.send("500 Unrecognized option." + '\r\n')
}
}
elseif(cmdLine == "CDUP"){
if(this.conn_list[hSocket].curr_dir == "/"){
return client.send("550 Failed." + '\r\n');
}
else {
this.conn_list[hSocket].curr_dir = ..fsys.getParentDir(this.conn_list[hSocket].curr_dir);
return client.send("200 Command okay." + '\r\n')
}
}
else{
if(arg == ""){
return client.send("500 No argument of: " + cmdLine + '\r\n');
}
if(!this.requestInfo(hSocket,arg)){
return client.send("500 Failed." + '\r\n');
}
if(cmdLine == "CWD"){
if(!this.conn_list[hSocket].request_info.existPath){
return client.send("500 Failed." + '\r\n');
}
if(!this.conn_list[hSocket].request_info.canRead){
return client.send("550 Permission denied." + '\r\n');
}
this.conn_list[hSocket].curr_dir = this.conn_list[hSocket].request_info.newPath;
return client.send("250 OK." + '\r\n');
}
elseif(cmdLine == "MDTM"){
if(!this.conn_list[hSocket].request_info.existFile){
return client.send("500 Failed." + '\r\n');
}
if(!this.conn_list[hSocket].request_info.canRead){
return client.send("550 Permission denied." + '\r\n');
}
var fpath = this.conn_list[hSocket].request_info.realPath ++ arg;
var file = ..fsys.file(fpath,"r");
var times = ..time(file.getTime().write).addhour(8);
file.close();
return client.send("213 " ++ ..string.format("%Y%m%d%I%M%S",times ) ++ '\r\n');
}
elseif(cmdLine == "SIZE"){
if(!this.conn_list[hSocket].request_info.existFile){
return client.send("500 Failed." + '\r\n');
}
if(!this.conn_list[hSocket].request_info.canRead){
return client.send("550 Permission denied." + '\r\n');
}
var fpath = this.conn_list[hSocket].request_info.realPath ++ this.conn_list[hSocket].request_info.fileName;
return client.send("231 " ++ ..io.getSize(fpath) ++ '\r\n');
}
elseif(cmdLine == "RNFR"){
if(!this.conn_list[hSocket].request_info.existPath){
return client.send("500 Failed." + '\r\n');
}
if(!this.conn_list[hSocket].request_info.canModify){
return client.send("550 Permission denied." + '\r\n');
}
this.conn_list[hSocket].temp_path = this.conn_list[hSocket].request_info.realPath;
return client.send("350 Rename from " ++ arg ++ '\r\n');
}
elseif(cmdLine == "RNTO"){
if(this.conn_list[hSocket].request_info.existPath){
return client.send("550 The path already exists." + '\r\n');
}
if(!this.conn_list[hSocket].temp_path){
return client.send("550 Failed." + '\r\n');
}
..fsys.rename(this.conn_list[hSocket].temp_path,this.conn_list[hSocket].request_info.realPath);
this.conn_list[hSocket].temp_path = null;
return client.send("250 OK.RNTO to " ++ arg ++ '\r\n');
}
elseif(cmdLine == "XMKD" or cmdLine == "MKD"){
if(this.conn_list[hSocket].request_info.existPath){
return client.send("550 The path already exists." + '\r\n');
}
if(!this.conn_list[hSocket].request_info.canModify){
return client.send("550 Permission denied." + '\r\n');
}
..io.createDir(this.conn_list[hSocket].request_info.realPath);
return client.send("250 OK." + '\r\n');
}
elseif(cmdLine == "XRMD" or cmdLine == "RMD"){
if(!this.conn_list[hSocket].request_info.existPath){
return client.send("550 The path not exists." + '\r\n');
}
if(!this.conn_list[hSocket].request_info.canModify){
return client.send("550 Permission denied." + '\r\n');
}
..fsys.delete(this.conn_list[hSocket].request_info.realPath);
return client.send("250 OK." + '\r\n');
}
elseif(cmdLine == "DELE"){
if(!this.conn_list[hSocket].request_info.existFile){
return client.send("550 The file not exists." + '\r\n');
}
if(!this.conn_list[hSocket].request_info.canModify){
return client.send("550 Permission denied." + '\r\n');
}
var fpath = this.conn_list[hSocket].request_info.realPath ++ arg;
..fsys.delete(fpath);
return client.send("250 OK." + '\r\n');
}
elseif(cmdLine == "RETR"){
if(!this.conn_list[hSocket].request_info.existFile){
return client.send("550 The file not exists." + '\r\n');
}
if(!this.conn_list[hSocket].request_info.canRead){
return client.send("550 Permission denied." + '\r\n');
}
var socket;
if(this.conn_list[hSocket].option_pasv){
if(this.conn_list[hSocket].data_fd == 0){
return client.send("425 Can't open data connection." + '\r\n')
}
acceptSocket = ..wsock.accept(this.conn_list[hSocket].data_fd);
if( acceptSocket == _INVALID_SOCKET ){
return client.send("425 Can't open data connection." + '\r\n')
}
socket = ..wsock.tcp.client(,acceptSocket);
}
else {
if(!this.conn_list[hSocket].data_ip or !this.conn_list[hSocket].data_port){
return client.send("500 Failed." + '\r\n');
}
socket = ..wsock.tcp.client();
if( !socket.connect(this.conn_list[hSocket].data_ip,this.conn_list[hSocket].data_port) ){
return client.send("425 Can't open data connection." + '\r\n')
}
}
var fpath = this.conn_list[hSocket].request_info.realPath ++ this.conn_list[hSocket].request_info.fileName;
var file,err = ..io.open(fpath,"r+b");
if( file ){
client.send("150 Opening binary mode data connection for file transfer. " + '\r\n');
while(var data;data = file.read(1024);data != null){
socket.send(data,#data);
}
file.close();
socket.close();
this.conn_list[hSocket].data_fd = 0;
return client.send("226 Transfer complete." + '\r\n');
}
else {
socket.close();
this.conn_list[hSocket].data_fd = 0;
return client.send("550 Open file failed." + '\r\n');
}
}
elseif(cmdLine == "STOR" or cmdLine == "APPE"){
if(this.conn_list[hSocket].request_info.existFile and cmdLine != "APPE"){
return client.send("550 The file already exists." + '\r\n');
}
if(!this.conn_list[hSocket].request_info.canWrite){
return client.send("550 Permission denied." + '\r\n');
}
var socket;
if(this.conn_list[hSocket].option_pasv){
if(this.conn_list[hSocket].data_fd == 0){
return client.send("425 Can't open data connection." + '\r\n')
}
acceptSocket = ..wsock.accept(this.conn_list[hSocket].data_fd);
if( acceptSocket == _INVALID_SOCKET ){
return client.send("425 Can't open data connection." + '\r\n')
}
socket = ..wsock.tcp.client(,acceptSocket);
}
else {
if(!this.conn_list[hSocket].data_ip or !this.conn_list[hSocket].data_port){
return client.send("500 Failed." + '\r\n');
}
socket = ..wsock.tcp.client();
if( !socket.connect(this.conn_list[hSocket].data_ip,this.conn_list[hSocket].data_port) ){
return client.send("425 Can't open data connection." + '\r\n')
}
}
var fpath = this.conn_list[hSocket].request_info.realPath ++ this.conn_list[hSocket].request_info.fileName;
var testPath = ..io.splitpath(fpath);
var testDir = testPath.dir;
if(!..io.exist(testDir)){
if(this.conn_list[hSocket].request_info.canModify){
..fsys.createDir(testDir);
}
else {
return client.send("550 Permission denied." + '\r\n');
}
}
client.send("150 Opening binary mode data connection for file transfer. " + '\r\n');
var file;
if(cmdLine == "STOR"){
file,err = ..io.open(fpath,"w+b") //注意io.open默认是文本方式读出的,b指定二进制模式
}
else {
file,err = ..io.open(fpath,"a+b") //注意io.open默认是文本方式读出的,b指定二进制模式
}
var buffer = ..raw.buffer(0x1000);
var size = ..math.size64();
for(readSize,remainSize in socket.eachReadBuffer(buffer) ){
file.writeBuffer(buffer,readSize);
}
file.close();
socket.close();
this.conn_list[hSocket].data_fd = 0;
return client.send("226 Transfer complete." + '\r\n');
}
else {
return client.send("502 Implement this later..." + '\r\n');
}
}
};
};
run = function(){
if(this.start(this.localIp,this.localPort)){
return true;
}
else {
return;
}
};
}
/**intellisense()
wsock.tcp.asynFtpServer() = 创建单线程异步FTP服务端\n!stdasynFtpServer.
end intellisense**/
/**intellisense(!stdasynFtpServer)
run() = 启动单线程异步TCP服务端,成功返回true,失败返回null,\n\nIP默认设为"192.168.x.x"段,端口省略为21
getLocalIp() = 返回当前绑定的IP,端口号
maxConnection = 最大连接数
keepAliveTimeout = 最大保持连接时间,以秒为单位,\n负数表示不限时间
documentRoot = FTP根目录,默认为"/"
identify = @.identify = function(username, password){
return true; //认证帐号返回true,否则返回false
__/*用户帐号合法性验证*/
}
permission = @.permission = function(userId,Path){
return read,write,modify; //相应文件夹,登录帐号读、写、修改权限
__/*用户帐号合法性验证*/
}
end intellisense**/
//使用演示
import win.ui;
/*DSG{{*/
var winform = win.form(text="FTP 服务器";right=759;bottom=469)
winform.add(
txtMessage={cls="edit";left=10;top=11;right=753;bottom=460;edge=1;font=LOGFONT(h=-20);multiline=1;vscroll=1;z=1}
)
/*}}*/
import win.ui.atom;
var atom,hwnd = winform.atom("736116B6-9CB7-415F-A4EB-052D28D8ABB1");
if(!atom){
/*为窗口设置原子值可以避免一个程序重复运行多个实例*/
win.quitMessage();
return;
}
FtpServer = asynFtpServer();
//演示帐号
var userAccount = {};
userAccount["admin"] = "admin";
userAccount["test"] = "123456";
userAccount["user"] = "pass";
//用户帐号合法性验证
FtpServer.identify = function(username, password){
if(userAccount[username] and password == userAccount[username]){
return true;
}
return false;
}
winform.onClose = function(hwnd,message,wParam,lParam){
FtpServer.stop();
}
if(FtpServer.run()){
winform.txtMessage.print("FTP服务器已启动:",FtpServer.localIp,FtpServer.localPort);
}
else {
winform.txtMessage.print("FTP服务器启动失败.");
}
winform.show();
win.loopMessage();