5 USES ServerLoop
,Chat
,SysUtils
,MemStream
,NetAddr
;
10 procedure Reply(msg
:tSMsg
; data
:boolean);
12 procedure Timeout(willwait
:LongWord
);
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
));
33 procedure t
.Timeout(willwait
:LongWord
);
35 if willwait
>=16000 then begin
36 writeln('TestChat: timeout, give up');
39 writeln('TestChat: resend willwait='+IntToStr(willwait
));
42 procedure t
.HardTimeout
;
44 writeln('TestChat: hardtimeout');
48 procedure ChatHandler(var nchat
:tChat
; msg
:tSMsg
);
54 setlength(d
,msg
.stream
.RDBufLen
);
55 msg
.stream
.read(d
[1],msg
.stream
.RDBufLen
);
58 s
.init(GetMem(56),0,56);
60 d
:='Test Chat Reply!';
61 s
.Write(d
[1],length(d
));
71 const opt
='-test-chat';
76 assert(OptParamCount(oi
)=1,opt
+'(rcpt:tNetAddr)');
77 writeln('TestChat: rcpt '+paramstr(oi
+1));
78 {init chat to rcpt, send message wait reply, print reply, done}
79 new(o
); with o
^ do begin
80 ch
.Init(paramstr(oi
+1));
82 ch
.DisposeHook
:=@Rekt
;
84 Shedule(7000,@HardTimeout
);
85 s
.init(GetMem(56),0,56);
87 msg
:='Test Chat Message!';
89 s
.Write(msg
[1],length(msg
));
93 SetChatHandler(32,@ChatHandler
);