Hello everyone,
a little bit of understanding with UDP
I use two UDP ports
the first fixed 52830 listens
the second parametrable between 49152 and 65535 sending (Main.UDPport)
my code is the following:
I get the used address error "used" while I seem to close the sockets and the ports are different
a little bit of understanding with UDP
I use two UDP ports
the first fixed 52830 listens
the second parametrable between 49152 and 65535 sending (Main.UDPport)
my code is the following:
B4X:
Sub Class_Globals
Dim Response, Error As StringBuilder
Dim UDPSocketReceived As UDPSocket
Dim UDPSocketSend As UDPSocket
End Sub
Public Sub Initialize
If Main.checked1 = True Then
UDPSocketReceived.Initialize("UDP", 52830, 8000)
End If
If Main.checked2= True Then
UDPSocketSend.Initialize("UDP", Main.UDPport, 8000)
End If
End Sub
Sub UDP_PacketArrived (Packet As UDPPacket)
Dim msg As String
msg = BytesToString(Packet.Data, Packet.Offset, Packet.Length, "UTF8")
log(msg)
End Sub
Sub UDP_SendPacket(Checked As String)
UDPSocketReceived.Close
UDPSocketSend.Initialize("UDP", Main.UDPport, 8000)
Dim Packet As UDPPacket
Dim data() As Byte
data = Checked.GetBytes("UTF8")
Packet.Initialize(data, Main.UDPhost, Main.UDPport)
UDPSocketSend.Send(Packet)
UDPSocketSend.Close
UDPSocketReceived.Initialize("UDP", 52830, 8000)
End Sub
netconnect_initialize (java line: 105)
java.net.BindException: bind failed: EADDRINUSE (Address already in use)
at libcore.io.IoBridge.bind(IoBridge.java:99)
at java.net.PlainDatagramSocketImpl.bind(PlainDatagramSocketImpl.java:60)
at java.net.DatagramSocket.createSocket(DatagramSocket.java:159)
at java.net.DatagramSocket.<init>(DatagramSocket.java:80)
at anywheresoftware.b4a.objects.SocketWrapper$UDPSocket.Initialize(SocketWrapper.java:444)
at com.bmwk100.dashboard.netconnect._initialize(netconnect.java:105)
at com.bmwk100.dashboard.main._vvvvvvvvvvvvvvvvvvvvvv4(main.java:1336)
at com.bmwk100.dashboard.main._vvvvvvvvvvvvvvvvvvvvv3(main.java:1193)
at com.bmwk100.dashboard.main._activity_create(main.java:515)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
at com.bmwk100.dashboard.main.afterFirstLayout(main.java:104)
at com.bmwk100.dashboard.main.access$000(main.java:17)
at com.bmwk100.dashboard.main$WaitForLayout.run(main.java:82)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5538)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:958)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:753)
Caused by: android.system.ErrnoException: bind failed: EADDRINUSE (Address already in use)
at libcore.io.Posix.bind(Native Method)
I get the used address error "used" while I seem to close the sockets and the ports are different