7 lcorewsaasyncselect in 'lcorewsaasyncselect.pas',
\r
21 procedure sessionavailable(sender: tobject;error : word);
\r
22 procedure dataavailable(sender: tobject;error : word);
\r
23 procedure sessionconnected(sender: tobject;error : word);
\r
24 procedure taskrun(wparam,lparam:longint);
\r
25 procedure timehandler(sender:tobject);
\r
26 procedure dnsrequestdone(sender:tobject;error : word);
\r
27 procedure sessionclosed(sender:tobject;error : word);
\r
30 listensocket : tlsocket;
\r
31 serversocket : tlsocket;
\r
32 clientsocket : tlsocket;
\r
35 procedure tsc.sessionavailable(sender: tobject;error : word);
\r
37 writeln('received connection');
\r
38 serversocket.dup(listensocket.accept);
\r
42 receivebuf : string;
\r
43 receivecount : integer;
\r
44 procedure tsc.dataavailable(sender: tobject;error : word);
\r
46 receiveddata : string;
\r
47 receivedon : string;
\r
50 receiveddata := tlsocket(sender).receivestr;
\r
51 if sender=clientsocket then begin
\r
52 receivedon := 'client socket';
\r
54 receivedon := 'server socket';
\r
56 writeln('received data '+receiveddata+' on '+receivedon);
\r
58 receivebuf := receivebuf+receiveddata;
\r
60 if receivebuf = 'hello world' then begin
\r
62 writeln('received hello world creating task');
\r
63 task := tltask.create(sc.taskrun,nil,0,0);
\r
65 receivecount := receivecount +1;
\r
66 if receivecount >50 then begin
\r
67 writeln('received over 50 bits of data, pausing to let the operator take a look');
\r
71 while pos(#10,receivebuf) > 0 do begin
\r
73 setlength(line,pos(#10,receivebuf)-1);
\r
74 receivebuf := copy(receivebuf,pos(#10,receivebuf)+1,1000000);
\r
75 if uppercase(copy(line,1,4))='PING' then begin
\r
77 writeln('send pong:'+line);
\r
78 clientsocket.sendstr(line+#10);
\r
83 procedure tsc.sessionconnected(sender: tobject;error : word);
\r
85 if error=0 then begin
\r
86 writeln('session is connected, local address is'+clientsocket.getxaddr);
\r
88 if (clientsocket.addr = '127.0.0.1') or (clientsocket.addr = '::1') then begin
\r
89 clientsocket.sendstr('hello world');
\r
91 clientsocket.sendstr('nick test'#13#10'user x x x x'#13#10);
\r
94 writeln('connect failed');
\r
101 procedure tsc.taskrun(wparam,lparam:longint);
\r
103 tempbinip : tbinip;
\r
106 writeln('task ran');
\r
107 writeln('closing client socket');
\r
108 clientsocket.close;
\r
110 writeln('looking up irc.ipv6.p10link.net using dnsasync');
\r
111 das := tdnsasync.Create(nil);
\r
112 das.onrequestdone := sc.dnsrequestdone;
\r
113 //das.forwardfamily := af_inet6;
\r
114 das.forwardlookup('irc.ipv6.p10link.net');
\r
117 procedure tsc.dnsrequestdone(sender:tobject;error : word);
\r
119 writeln('irc.ipv6.p10link.net resolved to '+das.dnsresult+' connecting client socket there');
\r
120 clientsocket.addr := das.dnsresult;
\r
121 clientsocket.port := '6667';
\r
122 clientsocket.connect;
\r
123 writeln(clientsocket.getxaddr);
\r
127 procedure tsc.timehandler(sender:tobject);
\r
129 //writeln('got timer event');
\r
131 procedure tsc.sessionclosed(sender:tobject;error : word);
\r
133 Writeln('session closed with error ',error);
\r
140 ipbin := forwardlookup('invalid.domain',5);
\r
141 writeln(ipbintostr(ipbin));
\r
143 ipbin := forwardlookup('p10link.net',5);
\r
144 writeln(ipbintostr(ipbin));
\r
146 ipstrtobin('80.68.89.68',ipbin);
\r
147 writeln('80.68.89.68 reverses to '+reverselookup(ipbin,5));
\r
149 ipstrtobin('2001:200::8002:203:47ff:fea5:3085',ipbin);
\r
150 writeln('2001:200::8002:203:47ff:fea5:3085 reverses to '+reverselookup(ipbin,5));
\r
151 writeln('creating and setting up listen socket');
\r
152 listensocket := tlsocket.create(nil);
\r
153 listensocket.addr := '::';
\r
154 listensocket.port := '12345';
\r
155 listensocket.onsessionavailable := sc.sessionavailable;
\r
156 writeln('listening');
\r
157 listensocket.listen;
\r
158 writeln(listensocket.getxport);
\r
159 writeln('listen socket is number ', listensocket.fdhandlein);
\r
160 writeln('creating and setting up server socket');
\r
161 serversocket := tlsocket.create(nil);
\r
162 serversocket.ondataavailable := sc.dataavailable;
\r
163 writeln('creating and setting up client socket');
\r
164 clientsocket := tlsocket.create(nil);
\r
165 clientsocket.addr := '::1';{'127.0.0.1';}
\r
166 clientsocket.port := '12345';
\r
167 clientsocket.onsessionconnected := sc.sessionconnected;
\r
168 clientsocket.ondataAvailable := sc.dataavailable;
\r
169 clientsocket.onsessionclosed := sc.sessionclosed;
\r
170 writeln('connecting');
\r
171 clientsocket.connect;
\r
172 writeln('client socket is number ',clientsocket.fdhandlein);
\r
173 writeln('creating and setting up timer');
\r
174 timer := tltimer.create(nil);
\r
175 timer.interval := 1000;
\r
176 timer.ontimer := sc.timehandler;
\r
177 timer.enabled := true;
\r
178 writeln('entering message loop');
\r
180 writeln('exiting cleanly');
\r