// Connecting to the server, disconnecting.
procedure TAndroidModule1.jButton1Click(Sender: TObject);
begin
if jButton1.Text='Connect' then begin
try
jTCPSocketClient1.SetDataTransferMode(dtmByte); // I don't use it in text mode.
jTCPSocketClient1.ConnectAsync('192.168.1.106', 1024);
except
ShowMessage('Error.');
end;
end else begin
jTCPSocketClient1.CloseConnection();
jButton1.Text:='Connect';
end;
end;
// The connection to the server has succeeded.
procedure TAndroidModule1.jTCPSocketClient1Connected(Sender: TObject);
begin
jButton1.Text:='Disconnect';
end;
// Transfer bytes.
procedure TAndroidModule1.jButton2Click(Sender: TObject);
var
Buf: TDynArrayOfJByte;
begin
if jButton1.Text='Connect' then exit;
SetLength(Buf,6);
Buf[0]:=1;
Buf[1]:=$01;
Buf[2]:=$08;
Buf[3]:=$00;
Buf[4]:=$00;
Buf[5]:=$10;
jTCPSocketClient1.SendBytes(Buf, true);
SetLength(Buf,0);
end;