Android Question tcp Socket problem

Devv

Active Member
Licensed User
Longtime User
Anyone can detect the problem ?

B4X:
Sub Process_Globals
    Dim ph As PhoneVibrate
    Dim tw As TextWriter
    Dim Socket1 As Socket
End Sub

Sub Globals
    Private Button6 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("main")
    Socket1.Initialize("Socket1")
    Socket1.Connect("192.168.1.111", 403, 20000)
End Sub

Sub Activity_Resume

End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub Button6_Click
    tw.Initialize(Socket1.OutputStream)
    tw.Writeline("Doner sandwich")
    tw.Flush
    Socket1.Close
    ToastMessageShow("Doner sandwich ?",False)
    ph.Vibrate(100)
End Sub

Sub Socket1_Connected (Successful As Boolean)
    If Successful = False Then
        Msgbox(LastException.Message, "Error connecting")
        Return
    End If
    ToastMessageShow("Connected successfully", False)
    Button6.Visible = True

End Sub
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Anybody their ?!!!!
Dont bump your questions! It is not liked here

Sure there is somebody... You can see it on threadlist how many times your question was read.
Saying for me only; i never used TCP-streams before in B4A so i did not have any thoughts i would like to share... So, in my case, i did not answer that thread...

BE PATIENT! Hopefully someone other will have an answer for you
 
Upvote 0

Devv

Active Member
Licensed User
Longtime User
You should be more patient.

While I see several problems in your code, you didn't write which problem did you encounter.

As a general rule, if you are using TextReader and TextWriter with a network stream then you are doing it incorrectly. You should always use AsyncStreams.

the problem is that i can't receive any data when i press button6 , am i'm sure my server is 100% working
i had seen the AsyncStreams but it hard i couldn't understand ,could you please paste here my same code but with AsyncStreams ?
or any AsyncStreams code that send a string using tcp
 
Upvote 0

Devv

Active Member
Licensed User
Longtime User
OK i will try to understand it ..
what about my code could you please correct it ?
thanks in advanced ..
 
Upvote 0
Top