G goehberry Member Licensed User Longtime User Mar 26, 2016 #1 Hi Everyone, in b4a i usually this code below Sub Process_Globals Dim txt As TextWriter Dim Socket1 As Socketend sub sub Testing Socket1.Initialize("Socket1") Socket1.Connect("192.168.1.168",9100,5000)end sub Sub Socket1_Connected(Connected As Boolean)As Boolean If Connected = True Then txt.Initialize(Socket1.OutputStream) txt.Write(pesan) txt.Flush txt.Close Socket1.Close End IfEnd Sub ini B4i, i couldn't find the replacement for Textwriter...I tried with AsyncStreamstext and AsyncStreams but it is not working like it should... Please help guys.... Thank you in advance
Hi Everyone, in b4a i usually this code below Sub Process_Globals Dim txt As TextWriter Dim Socket1 As Socketend sub sub Testing Socket1.Initialize("Socket1") Socket1.Connect("192.168.1.168",9100,5000)end sub Sub Socket1_Connected(Connected As Boolean)As Boolean If Connected = True Then txt.Initialize(Socket1.OutputStream) txt.Write(pesan) txt.Flush txt.Close Socket1.Close End IfEnd Sub ini B4i, i couldn't find the replacement for Textwriter...I tried with AsyncStreamstext and AsyncStreams but it is not working like it should... Please help guys.... Thank you in advance
aaronk Well-Known Member Licensed User Longtime User Mar 26, 2016 #2 It's the same code as B4A. - https://www.b4x.com/android/forum/threads/asyncstreams-tutorial.7669/#content Upvote 0
It's the same code as B4A. - https://www.b4x.com/android/forum/threads/asyncstreams-tutorial.7669/#content
Erel B4X founder Staff member Licensed User Longtime User Mar 27, 2016 #3 You should update your B4A code. It is a mistake to use TextWriter / TextReader with network connections (your app will eventually hang). Upvote 0
You should update your B4A code. It is a mistake to use TextWriter / TextReader with network connections (your app will eventually hang).
G goehberry Member Licensed User Longtime User Mar 31, 2016 #4 Hi Aaronk, Thanks I finally made it work... Hi Erel, my code in B4A was to print to network printer, and it was running okay. But maybe I miss something. Can you please advise what suppose to be the update? Thank you in advance! Upvote 0
Hi Aaronk, Thanks I finally made it work... Hi Erel, my code in B4A was to print to network printer, and it was running okay. But maybe I miss something. Can you please advise what suppose to be the update? Thank you in advance!
Erel B4X founder Staff member Licensed User Longtime User Apr 1, 2016 #5 You should remove TextReader and TextWriter and use AsyncStreams instead. Android doesn't allow making network calls on the main thread. Upvote 0
You should remove TextReader and TextWriter and use AsyncStreams instead. Android doesn't allow making network calls on the main thread.