Addo Well-Known Member Licensed User Longtime User Mar 4, 2018 #1 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 Code: Copy Socket1.Initialize("Socket1") Socket1.Connect("machine ip" , 27274, 20000) ph.KeepAlive(True) and this is how i write Code: Copy 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: Aug 14, 2018
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 Code: Copy Socket1.Initialize("Socket1") Socket1.Connect("machine ip" , 27274, 20000) ph.KeepAlive(True) and this is how i write Code: Copy 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
aaronk Well-Known Member Licensed User Longtime User Mar 4, 2018 #2 Check out: https://www.b4x.com/android/forum/threads/b4x-asyncstreams-tutorial.7669/ Upvote 0
Addo Well-Known Member Licensed User Longtime User Mar 4, 2018 #3 My server doesn't write streams only its also writestrings in the same protocol using write/writeln Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Mar 4, 2018 #4 PassionDEV said: and this is how i write Click to expand... Never use TextWriter with network streams. Upvote 0
PassionDEV said: and this is how i write Click to expand... Never use TextWriter with network streams.
Addo Well-Known Member Licensed User Longtime User Mar 4, 2018 #5 Erel said: Never use TextWriter with network Click to expand... I am just confused my server sends text over wire not as stream uses writeln I am not sure how to read that data using asyncstream sense my server does not write streams also sending as well Upvote 0
Erel said: Never use TextWriter with network Click to expand... I am just confused my server sends text over wire not as stream uses writeln I am not sure how to read that data using asyncstream sense my server does not write streams also sending as well
Erel B4X founder Staff member Licensed User Longtime User Mar 4, 2018 #6 Have you seen the complete video? Upvote 0
Addo Well-Known Member Licensed User Longtime User Mar 4, 2018 #8 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
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
Erel B4X founder Staff member Licensed User Longtime User Mar 4, 2018 #9 Network communication is always done with arrays of bytes. You can convert a string to an array of bytes with "aaa".GetBytes("UTF8") and convert it back with BytesToString. Maybe it will be easier to start with this example: [B4X] Network + AsyncStreams + B4XSerializator Upvote 0
Network communication is always done with arrays of bytes. You can convert a string to an array of bytes with "aaa".GetBytes("UTF8") and convert it back with BytesToString. Maybe it will be easier to start with this example: [B4X] Network + AsyncStreams + B4XSerializator
Addo Well-Known Member Licensed User Longtime User Mar 4, 2018 #10 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
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 ?
Erel B4X founder Staff member Licensed User Longtime User Mar 4, 2018 #11 Your delphi server already sends bytes. You can use BytesToString to convert the received bytes back to a string. If each message ends with an end of line character then you can use AsyncStreamsText. Upvote 0
Your delphi server already sends bytes. You can use BytesToString to convert the received bytes back to a string. If each message ends with an end of line character then you can use AsyncStreamsText.
Addo Well-Known Member Licensed User Longtime User Mar 4, 2018 #12 I will dig deep into this and will come back with feedback I am sure this topic will help other delphi developers who wants to migrate Thank you for your patience Upvote 0
I will dig deep into this and will come back with feedback I am sure this topic will help other delphi developers who wants to migrate Thank you for your patience
asales Expert Licensed User Longtime User Mar 4, 2018 #13 Maybe you need to try a different aproach or other components in Delphi, like the Indy components and REST Webservice. See if this links can help you: http://www.drdobbs.com/web-development/restful-web-services-a-tutorial/240169069?pgno=1 https://delphisolutions.wordpress.com/2015/12/07/rest-webservice-em-delphi-com-indy-sem-datasnap/ (in portuguese) Upvote 0
Maybe you need to try a different aproach or other components in Delphi, like the Indy components and REST Webservice. See if this links can help you: http://www.drdobbs.com/web-development/restful-web-services-a-tutorial/240169069?pgno=1 https://delphisolutions.wordpress.com/2015/12/07/rest-webservice-em-delphi-com-indy-sem-datasnap/ (in portuguese)
Addo Well-Known Member Licensed User Longtime User Mar 4, 2018 #14 This is not indy tcp problem , I was able to connect and communicate using writeln if you read my first post, the problem is I dont know how to writeln and readln using asyncstream . Upvote 0
This is not indy tcp problem , I was able to connect and communicate using writeln if you read my first post, the problem is I dont know how to writeln and readln using asyncstream .
Addo Well-Known Member Licensed User Longtime User Mar 4, 2018 #16 I am not very expert in b4a this is just my day 1 can you explain with code by not using prefix mode please Upvote 0
I am not very expert in b4a this is just my day 1 can you explain with code by not using prefix mode please
OliverA Expert Licensed User Longtime User Mar 4, 2018 #17 PassionDEV said: astream.InitializePrefix Click to expand... Just use astream.Initialize Upvote 0
Addo Well-Known Member Licensed User Longtime User Mar 4, 2018 #18 What is the different and how this will make asteam use writeln / readln ? Not bytes Upvote 0
OliverA Expert Licensed User Longtime User Mar 4, 2018 #19 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
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.
Addo Well-Known Member Licensed User Longtime User Mar 5, 2018 #20 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
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 ?