1 { KOL MCK } // Do not remove this line!
\r
8 uses Windows, Messages, ShellAPI, KOL {$IFNDEF KOL_MCK}, mirror, Classes,
\r
9 Controls, mckCtrls {$ENDIF},KOLWSocket,WinSock;
\r
12 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
\r
18 {$I MCKfakeClasses.inc}
\r
19 {$IFDEF KOLCLASSES} TForm1 = class; PForm1 = TForm1; {$ELSE OBJECTS} PForm1 = ^TForm1; {$ENDIF CLASSES/OBJECTS}
\r
20 {$IFDEF KOLCLASSES}{$I TForm1.inc}{$ELSE} TForm1 = object(TObj) {$ENDIF}
\r
23 TForm1 = class(TForm)
\r
25 KOLProject1: TKOLProject;
\r
27 DisconnectButton: TKOLButton;
\r
28 InfoLabel: TKOLLabel;
\r
29 procedure KOLForm1Show(Sender: PObj);
\r
30 procedure KOLForm1FormCreate(Sender: PObj);
\r
31 procedure DisconnectButtonClick(Sender: PObj);
\r
32 procedure KOLForm1KeyDown(Sender: PControl; var Key: Integer;
\r
35 { Private declarations }
\r
37 { Public declarations }
\r
38 procedure SrvSocketSessionAvailable(Sender: PObj; Error: Word);
\r
39 procedure CliSocketSessionClosed(Sender: PObj; Error: Word);
\r
43 Form1 {$IFDEF KOL_MCK} : PForm1 {$ELSE} : TForm1 {$ENDIF} ;
\r
44 SrvSocket: PWSocket;
\r
45 CliSocket: PWSocket;
\r
46 FirstTime:Boolean=true;
\r
49 procedure NewForm1( var Result: PForm1; AParent: PControl );
\r
54 {$IFNDEF KOL_MCK} {$R *.DFM} {$ENDIF}
\r
60 procedure TForm1.SrvSocketSessionAvailable(Sender: PObj; Error: Word);
\r
62 NewHSocket : TSocket;
\r
63 PeerName : TSockAddrIn;
\r
66 { We need to accept the client connection }
\r
67 NewHSocket := SrvSocket.Accept;
\r
69 { And then associate this connection with our client socket }
\r
70 CliSocket.Dup(NewHSocket);
\r
72 { Wants to know who is connected to display on screen }
\r
73 CliSocket.GetPeerName(PeerName, Sizeof(PeerName));
\r
75 { User likes to see internet address in dot notation }
\r
76 Peer := Int2Str(ord(PeerName.sin_addr.S_un_b.s_b1)) + '.' +
\r
77 Int2Str(ord(PeerName.sin_addr.S_un_b.s_b2)) + '.' +
\r
78 Int2Str(ord(PeerName.sin_addr.S_un_b.s_b3)) + '.' +
\r
79 Int2Str(ord(PeerName.sin_addr.S_un_b.s_b4));
\r
80 InfoLabel.Caption := 'Remote ' + Peer + ' connected';
\r
82 { Send a welcome message to the client }
\r
83 CliSocket.SendStr('Hello' + #13 + #10);
\r
85 { Enable the server user to disconect the client }
\r
86 DisconnectButton.Enabled := TRUE;
\r
89 procedure TForm1.CliSocketSessionClosed(Sender: PObj; Error: Word);
\r
91 DisconnectButton.Enabled := FALSE;
\r
92 InfoLabel.Caption := 'Waiting for client';{ Inform the user }
\r
95 procedure TForm1.KOLForm1Show(Sender: PObj);
\r
100 FirstTime := FALSE; { Do it only once ! }
\r
101 SrvSocket.Addr := '0.0.0.0'; { Use any interface }
\r
102 SrvSocket.Listen; { Start listening for client }
\r
103 InfoLabel.Caption := 'Waiting for client';
\r
107 procedure TForm1.KOLForm1FormCreate(Sender: PObj);
\r
109 SrvSocket:=NewWSocket(nil);
\r
110 SrvSocket.Port:='telnet';
\r
111 CliSocket:=NewWSocket(nil);
\r
112 CliSocket.Port:='telnet';
\r
114 SrvSocket.OnSessionAvailable:=SrvSocketSessionAvailable;
\r
115 CliSocket.OnSessionClosed:=CliSocketSessionClosed;
\r
118 procedure TForm1.DisconnectButtonClick(Sender: PObj);
\r
120 CliSocket.ShutDown(2); { Shut the communication down }
\r
121 CliSocket.Close; { Close the communication }
\r
125 procedure TForm1.KOLForm1KeyDown(Sender: PControl; var Key: Integer;
\r
128 ShowMessage(Int2Str(Shift));
\r