Start UDP-Server

Pfanne

New Member
Licensed User
Longtime User
Hi,

i try to start a UDP-Server in listening-mode,
but the port is not open.

B4X:
Sub Process_Globals
  Dim UDPSocket2 As ServerSocket
End Sub

Sub Activity_Create(FirstTime As Boolean)
  Activity.LoadLayout("main")
  If FirstTime Then
    UDPSocket2.Initialize(33333, "UDP")
  End If
End Sub

Sub Activity_Resume
  UDPSocket2.Listen
End Sub

Sub UDP_PacketArrived (Packet As UDPPacket)
  If Packet.Port = 33333 Then Log("33333")
End Sub

What did i wrong?

Thanks for yor help.
Greetings from germany
Pf@nne
 

Pfanne

New Member
Licensed User
Longtime User
Hi Erel,

thanks for your answer.

Packet.Port returns the port in the device that sent the packet

OK, but in Wireshark i see that port 33333 ist not reachable.
If i send UDP to port 33333 nothing happends.

This schould be show all recheived Data on ervery Port, isent it?
B4X:
Sub UDP_PacketArrived (Packet As UDPPacket)
    Dim msg As String
    msg = BytesToString(Packet.Data, Packet.Offset, Packet.Length, "UTF8")
    Msgbox("Message received: " & msg, "")
End Sub

Is my code in post #1, to open a UDP-Server in listenig mode on port 33333 OK?

Thanks for your Help
Pf@nne
 
Upvote 0

Pfanne

New Member
Licensed User
Longtime User
Hello Erel,

i also use the UDP-Socket to send UDP-Data and receive the response from the far server.

I think the used UDP-Socket is, after sending, only a limeted time in listenig (Server) Mode on the random Port

How to set the UDP-Socket permanent in listening Mode on Port xxxxx?


Greets
Pf@nne
 
Last edited:
Upvote 0

Pfanne

New Member
Licensed User
Longtime User
Hi Erel,

of course you were absolutely right!

But my port 33333 is only in my home-LAN reachable.
With dissabled WLAN the port is over the WAN,
by using the current mobile IP, not reachable.

As I said, after sending a UDP i received Data on the random send-port over the WAN.

It seams that there is any thing like a firewall....

Do you have a idea what i do wrong.......

Thanks for your quick support
greets from germany
Pf@nne
 
Upvote 0
Top