May i know how to connect multiple clients, having same PORT number, to a ServerSocket.
I could only get 1 client to connect at any time.
May i know what i do wrong?
sorry, i do not understand how to implement the similar in "https://www.b4x.com/android/forum/threads/b4j-cctv-example.34695/#post-203347"
Please advise. Thanks
B4A Server code
Python RaspberryPi multiple Clients code, all having same port, 2222.
I could only get 1 client to connect at any time.
May i know what i do wrong?
sorry, i do not understand how to implement the similar in "https://www.b4x.com/android/forum/threads/b4j-cctv-example.34695/#post-203347"
Please advise. Thanks
B4A Server code
B4X:
Sub Process_Globals
Dim AStreams1 As AsyncStreams
Dim Server1 As ServerSocket
Dim Socket1 As Socket
End Sub
Sub Activity_Create(FirstTime As Boolean)
Server1.Initialize(2222, "Server1")
Server1.Listen
End If
Sub Server1_NewConnection (Successful As Boolean, NewSocket As Socket)
If Successful Then
ToastMessageShow("Connected_Client", False)
Socket1 = NewSocket
AStreams1.Initialize(Socket1.InputStream, Socket1.OutputStream, "AStreams1")
Else
ToastMessageShow(LastException.Message, True)
End If
Server1.Listen
End Sub
Sub AStreams1_NewData (Buffer() As Byte)
Dim msg As String
msg = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
ToastMessageShow(msg, False)
Log(msg)
End Sub
Sub AStreams1_Error
ToastMessageShow(LastException.Message, True)
End Sub
Sub SendMessage
Dim str As String
str = "Test"
AStreams1.Write(str.GetBytes("UTF8"))
End Sub
Python RaspberryPi multiple Clients code, all having same port, 2222.
B4X:
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM )
host = '192.168.43.1'
print(host)
port = 2222
s.connect((host,port))
Last edited: