Network

Heinz

Active Member
Licensed User
Longtime User
i need a simple TCP-client with a Listview.
the samples that i found are too difficult.

I have written a PC - program. this works as server
and if a client is connected, it send the rows in a
Listview as string.

now i need a simple program that open a port,
read lines if is incomming strings, and write
these strings in an listview to show. furhter
i will separate the strings for writing in a table.

must only work on my private WIFI, not internet.

Has someone a little bit code ?
 

Heinz

Active Member
Licensed User
Longtime User
i have playing with it, but what are
the parameters of this sub ?
Sub Socket1_Connected(....)

End Sub

and here my code :

B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
    Dim Serversocket1 As ServerSocket
   Dim Socket1 As Socket
   Dim Timer1 As Timer
   Dim input1 As InputStream
   Dim output1 As OutputStream
   
End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

   Dim Button1 As Button
   Dim Button2 As Button
   Dim ListView1 As ListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    Button1.Text = "Connect"
   Button2.Text = "Close"
   Listview1.Clear
   Socket1.Initialize("Socket1")
   
End Sub


Sub Activity_Resume
    'Socket1.Listen
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    If UserClosed Then
      Timer1.Enabled = False
      Socket1.Close
      ServerSocket1.Close
   End If   
End Sub

Sub Button1_Click
    If Socket1.IsInitialized = True Then
      Socket1.Connect("192.168.178.33", 6832, 0)
      If Socket1.Connected = True Then
          Msgbox("Connected", "Info")
      End If
   End If
End Sub

Sub Button2_Click
    If Socket1.Connected = True Then
      Socket1.Close
   End If   
End Sub

Sub Socket1_Connected

End Sub

Sub Socket1_NewConnection(Successfull As Boolean, NewSocket As Socket)
Dim text As String
'Dim Buffer(100) As Byte
If Successfull Then
   text = Socket1.OutputStream
'   text = BytesToString(Buffer, 0, 100, "UTF-8")
   Listview1.AddSingleLine(text)
   
End If
End Sub
 
Upvote 0

Heinz

Active Member
Licensed User
Longtime User
Now, i can connect my PC with my device.
but if i want get data from my PC with
text = Socket1.InputStream,
this entries in the Listview i get :

org.apache.harmony.luni.net.
SocketInputStream@4a486d38

what is this ? :sign0163:
 
Upvote 0
Top