unit frmMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Menus, ComCtrls,Winsock, untListen, untClient;
type
TForm4 =
class(TForm)
StatusBar1: TStatusBar;
ListView1: TListView;
PopupMenu1: TPopupMenu;
Listen1: TMenuItem;
Disconnect1: TMenuItem;
SendMessage1: TMenuItem;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure Disconnect1Click(Sender: TObject);
procedure SendMessage1Click(Sender: TObject);
procedure Listen1Click(Sender: TObject);
procedure Status(Data: AnsiString);
private
Listen: TListener;
{ Private declarations }
public
hServer: TSocket;
intPort: Integer;
{ Public declarations }
end;
var
Form4: TForm4;
implementation
procedure TForm4.Disconnect1Click(Sender: TObject);
var
TmpClient:TClient;
begin
if assigned(ListView1.Selected)
then begin
TmpClient:=ListView1.Selected.data;
TmpClient.ListItem:=ListView1.Selected;
TmpClient.RemoveClient;
end;
end;
procedure TForm4.FormCreate(Sender: TObject);
begin
listview1.Column[2].Width := 150;
end;
procedure TForm4.Listen1Click(Sender: TObject);
var
wsaData: TWSAData;
TmpStr:AnsiString;
begin
//Declare a port to listen on
TmpStr:=InputBox('
Listen port','
Specify a port to open on for connections','
12345');
if trim(TmpStr) <> '
'
then
begin
IntPort:=StrToInt(TmpStr);
//Initialize and create our socket to accept connections with
WSAStartup($0202, wsaData);
Listen := TListener.Create(True);
with Listen
do
begin
FreeOnTerminate := True;
wPort := intPort;
Resume;
end;
end;
end;
procedure TForm4.SendMessage1Click(Sender: TObject);
Var
TmpClient:TClient;
TmpStr:AnsiString;
begin
if assigned(ListView1.Selected)
then begin
TmpStr:=Inputbox('
Send data to server','
Specify message data to send','
Hello from client');
if Trim(TmpStr) <> '
'
then begin
//Declare our client for sending data
TmpClient:=Listview1.selected.data;
TMPClient.ListItem:=Listview1.selected;
TmpClient.SendData('
MSGBOX' + '
|' + TmpStr);
end;
end;
end;
procedure TForm4.Status(Data: AnsiString);
begin
//Output our status message data
StatusBar1.Panels.Items[0].Text := '
Socket Status: ' + Data;
end;
{$R *.dfm}
end.