Android Question convert my delphi code to b4a

Addo

Well-Known Member
Licensed User
Longtime User
i am using delphi for almost 7 years and i need to convert my client Thread to B4A to work under service

i have read on tha forums on how to use socket and i come up with result like following

thats how to connect

B4X:
Socket1.Initialize("Socket1")
   Socket1.Connect("machine ip" , 27274, 20000)
   ph.KeepAlive(True)

and this is how i write

B4X:
If Socket1.Connected Then
         
tr.Initialize(Socket1.OutputStream)
tr.WriteLine(cmd)
tr.Flush
 End If

but i couldn't figure out how to do the same mechanism of my delphi code under b4a like using thread and readln and read stream continuously if a data available

i just wanted to convert from delphi to b4a
 
Last edited:

Addo

Well-Known Member
Licensed User
Longtime User
I have watched the full video great tutorial , but I am still confused the whole client and server you demonstrate is writing buffer , my server does not write a buffer the client should waiting for string or I am messed up in understanding
 
Upvote 0

Addo

Well-Known Member
Licensed User
Longtime User
What I meant is my server is already done by delphi I am not trying to create a server from scratch , I wanted to create a client to connect and communicate to that Delphi server.

Difficult understanding :

If the client is waiting for byets data the server should send byets data as well which I cannot do because I can't modify the delphi server because its been used for other apps which I cannot change its mechanism .

The server used writeln/write to send the data to the client

What I am confused about that this streams reading and byets should read whats incomming from server even if its writeln ?
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Don' use prefix mode?
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Please check out the link provided by @aaronk in post #2. It will explain Prefix mode. It also shows how to convert bytes to text and text to bytes. @Erel tried to tell you that under the hood, everything is bytes. Delphi just hides the fact from you and with B4X (be it B4A, B4i, B4J) you just have to do a little bit of converting.
 
Upvote 0

Addo

Well-Known Member
Licensed User
Longtime User
fine i have tried to use readbyets in the delphi server now i got gibberish characters which is invalid encoding i already used UTF8 encoding

CallSub2(Starter, "SendData", Bconv.StringToBytes(typingtxt.Text&"~", "UTF8"))

what could be the problem now ?
 
Upvote 0
Top