Java2 codes,problems ,discussions and solutions are here
Sat Jul 31, 2010 5:26 am
1.Client
procedure TForm1.ButtonKoneksiClick(Sender: TObject);
begin
if ClientSocket1.Active then
begin
ClientSocket1.Active := false;
end
else
begin
ClientSocket1.Address := EditIPServer.Text;
ClientSocket1.Port := StrToInt(EditPortServer.Text);
ClientSocket1.Active := true;
end;
end;
procedure TForm1.ClientSocket1Connecting(Sender: TObject;
Socket: TCustomWinSocket);
begin
LabelStatusKoneksi.Caption := 'Mencoba koneksi ke server';
end;
procedure TForm1.ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
begin
LabelStatusKoneksi.Caption := 'Terkoneksi ke server';
ButtonKoneksi.Caption := 'Putuskan Koneksi'
end;
procedure TForm1.ClientSocket1Disconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
LabelStatusKoneksi.Caption := 'Tidak terkoneksi ke server';
ButtonKoneksi.Caption := 'konek ke server';
end;
procedure TForm1.ClientSocket1Error(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
LabelStatusKoneksi.Caption :=
'Terjadi error saat koneksi ke server';
ErrorCode := 0;
end;
procedure TForm1.ButtonkirimClick(Sender: TObject);
begin
if ClientSocket1.Active then
ClientSocket1.Socket.SendText(EditData.Text)
else
ShowMessage('Koneksi tidak aktif');
end;
end.
2.Server
procedure TForm1.ButtonJalankanClick(Sender: TObject);
begin
if ServerSocket1.Active then
begin
ServerSocket1.Active := false;
LabelStatusServer.Caption := 'Server tidak aktif';
ButtonJalankan.Caption := 'Jalankan server';
end
else
begin
ServerSocket1.Port := StrToInt(EditPortServer.Text);
ServerSocket1.Active := true;
LabelStatusServer.Caption := 'Server aktif mendengarkan klien';
ButtonJalankan.Caption := 'Matikan server';
end;
end;
procedure TForm1.ServerSocket1ClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
LabelKlien.Caption := 'Klien terkoneksi dari'+ Socket.RemoteAddress;
end;
procedure TForm1.ServerSocket1ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
LabelKlien.Caption := 'Tidak ada klien terkoneksi';
end;
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
begin
Memo1.Lines.Add(Socket.ReceiveText);
end;
end.
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.