santook
Member
When I try to use the following code for TCP communication, I can connect multiple times using the TCP debugging tool, and they all show that they have been connected. But only the first connected client can send and receive data, why?
Multiple TCP connection communication:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private xui As XUI
Private tcps As ServerSocket
Private a As List
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
Private ListView1 As ListView
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout")
a.Initialize
tcps.Initialize(8099,"tcps")
tcps.Listen()
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
For i= 0 To a.Size-1
a.Get(i).As(AsyncStreams).Write("Hello".GetBytes("ASCII"))
Next
End Sub
Sub tcps_NewConnection (Successful As Boolean, NewSocket As Socket)
Dim x As AsyncStreams
x.Initialize(NewSocket.InputStream,NewSocket.OutputStream,"ass")
a.Add(x)
End Sub
Sub ass_NewData (Buffer() As Byte)
ListView1.AddSingleLine(BytesToString(Buffer,0,Buffer.Length,"ASCII"))
End Sub