5 USES ServerLoop
,Chat
,SysUtils
,MemStream
,NetAddr
;
10 procedure Reply(msg
:tSMsg
; data
:boolean);
13 procedure HardTimeout
;
16 procedure t
.Reply(msg
:tSMsg
; data
:boolean);
21 setlength(d
,msg
.stream
.RDBufLen
);
22 msg
.stream
.read(d
[1],msg
.stream
.RDBufLen
);
24 end else writeln('ack');
29 writeln('TestChat: rekt');
30 FreeMem(@self
,sizeof(self
));
35 writeln('TestChat: timeout, give up');
39 procedure t
.HardTimeout
;
41 writeln('TestChat: hardtimeout');
45 procedure ChatHandler(var nchat
:tChat
; msg
:tSMsg
);
51 setlength(d
,msg
.stream
.RDBufLen
);
52 msg
.stream
.read(d
[1],msg
.stream
.RDBufLen
);
55 s
.init(GetMem(56),0,56);
57 d
:='Test Chat Reply!';
58 s
.Write(d
[1],length(d
));
68 const opt
='-test-chat';
73 assert(OptParamCount(oi
)=1,opt
+'(rcpt:tNetAddr)');
74 writeln('TestChat: rcpt '+paramstr(oi
+1));
75 {init chat to rcpt, send message wait reply, print reply, done}
76 new(o
); with o
^ do begin
77 ch
.Init(paramstr(oi
+1));
80 ch
.OnTimeout
:=@Timeout
;
81 //Shedule(7000,@HardTimeout);
82 s
.init(GetMem(56),0,56);
83 ch
.SetTimeout(6000,8000);
85 msg
:='Test Chat Message!';
87 s
.Write(msg
[1],length(msg
));
91 SetChatHandler(32,@ChatHandler
);