Forum > Android
Can't send bytes via jTCPSocketClient
(1/1)
shyub:
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 [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---// 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;If the transfer is in text mode, then everything is fine:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TAndroidModule1.jButton3Click(Sender: TObject);begin if jButton1.Text='Connect' then exit; jTCPSocketClient1.SendMessage('11800F');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:
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;
--- End quote ---
shyub:
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:
What is your goal sending byte to the server my friend?
Navigation
[0] Message Index