Recent

Author Topic: Can't send bytes via jTCPSocketClient  (Read 748 times)

shyub

  • Full Member
  • ***
  • Posts: 124
Can't send bytes via jTCPSocketClient
« on: July 01, 2022, 01:09:27 pm »
You need to send the command "$01, $01, $08, $00, $00, $10" to the server. However, the server does not receive anything.
I do it like this:
Code: Pascal  [Select][+][-]
  1. // Connecting to the server, disconnecting.
  2. procedure TAndroidModule1.jButton1Click(Sender: TObject);
  3. begin
  4.   if jButton1.Text='Connect' then begin
  5.     try
  6.       jTCPSocketClient1.SetDataTransferMode(dtmByte); // I don't use it in text mode.
  7.       jTCPSocketClient1.ConnectAsync('192.168.1.106', 1024);
  8.     except
  9.       ShowMessage('Error.');
  10.     end;
  11.   end else begin
  12.     jTCPSocketClient1.CloseConnection();
  13.     jButton1.Text:='Connect';
  14.   end;
  15. end;
  16. // The connection to the server has succeeded.
  17. procedure TAndroidModule1.jTCPSocketClient1Connected(Sender: TObject);
  18. begin
  19.   jButton1.Text:='Disconnect';
  20. end;
  21. // Transfer bytes.
  22. procedure TAndroidModule1.jButton2Click(Sender: TObject);
  23. var
  24.   Buf: TDynArrayOfJByte;
  25. begin
  26.   if jButton1.Text='Connect' then exit;
  27.   SetLength(Buf,6);
  28.   Buf[0]:=1;
  29.   Buf[1]:=$01;
  30.   Buf[2]:=$08;
  31.   Buf[3]:=$00;
  32.   Buf[4]:=$00;
  33.   Buf[5]:=$10;
  34.   jTCPSocketClient1.SendBytes(Buf, true);  
  35.   SetLength(Buf,0);
  36. end;
If the transfer is in text mode, then everything is fine:
Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.jButton3Click(Sender: TObject);
  2. begin
  3.    if jButton1.Text='Connect' then exit;
  4.    jTCPSocketClient1.SendMessage('11800F');
  5. end;
A client written under WINDOWS based on INDI does not cause problems.
And data from jTCPSocketClient in byte transfer mode simply does not arrive at the server...
What could be my mistake?

If necessary, I can post the client and server code for Windows and the client code for Android.

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: Can't send bytes via jTCPSocketClient
« Reply #1 on: July 01, 2022, 11:37:31 pm »

Hi, shyub!

Just as a side note:
(that still doesn't solve your issue.... sorry...)

Quote
We are using pascal "shortint" to simulate the [Signed] java byte ....
      however "shortint" works in the range "-127 to 128" equal to the byte in java ....
      So every time we assign a value outside this range, for example 192, we get
      the "range check" message...

      How to Fix:

      var
        bufferToSend: array of jbyte; //jbyte = shortint
      begin
        ...........
        bufferToSend[0] := ToSignedByte($C0);    //<-- fixed!
        ........
      end;
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

shyub

  • Full Member
  • ***
  • Posts: 124
Re: Can't send bytes via jTCPSocketClient
« Reply #2 on: July 02, 2022, 07:25:17 am »
Is there a way to write an application using LAMW to send commands in bytes to the server?
There is just a device that I would like to control from my phone (after all, a laptop is not always at hand ...).

Mongkey

  • Sr. Member
  • ****
  • Posts: 430
Re: Can't send bytes via jTCPSocketClient
« Reply #3 on: July 02, 2022, 01:06:03 pm »
What is your goal sending byte to the server my friend?

 

TinyPortal © 2005-2018