Can we start with the client to clarify what it’s all about?
You have to read out the IP address of the Hanyd. WiFi mind you!
You need that later to make it clear to the class who (I) is sending.
We can not change these. So a “set” does not make sense here.
Then we open a receiver. It’s always online and waiting for events. A simple client application does not need access to open or shit.
public class UDPServer
public static void main (String  args) throws IOException
DatagramSocket socket = new DatagramSocket (*****);
The top of the stars must be set by the user of your extension!
This is the port we open. To my knowledge
Then we wait for the message
That should look like that in wtwas. Unfortunately no Java can not.
// wait on request
DatagramPacket packet = new DatagramPacket (new byte , 1024);
// read receiver
InetAddress address = packet.getAddress ();
int port = packet.getPort ();
int len = packet.getLength ();
byte  data = packet.getData ();
From “packet.getLength ();” and “packet.getData ();” then you have to send the message as a string to the extension. That already worked well.
“Packet.getPort ();” and “packet.getAddress ();” mus be offered to the user, because otherwise he will not know where his possible answer should be spoken.
!!! These details are time critical. !!!
You have to hang her on that one event.
They belong to the one message.
You have no guarantee that in the meantime a new package does not arrive during processing. Maybe create an Arrey with a buffer?
5 to 10 messages should be enough.
Then maybe close the server and open it again, if the buffer has room in your Arrey. The “programmer” will therefore hardly want to worry or can. (See broadcast!)
This is the event that should be used in the “programs” in the App Inventor.
This mus must now read and process. Whatever he does with it?
The recipient usually stays always open.
InetAddress ia = ****************. GetByName ("localhost");
String s = MESSAGE
byte  raw = s.getBytes ();
DatagramPacket packet = new DatagramPacket (raw, raw.length, ia, *****);
DatagramSocket dSocket = new DatagramSocket ();
For the stars in turn the port is specified, which is open at the recipient.
As well as the IP address of the recipient.
Where you see localhost, the open IP address of your own recipient must be specified!
In the case of broadcast this triggers a collapse of the network because you are using the recipient’s address here.
If that’s zero, just ignore it.
Much is not waiting for an answer. Much about UPD just goes out without waiting for an answer.
You can just leave the false / true away.
You read the recipient’s address and notice the last group of the IP.
If it’s 255, it’s broadcast. Yue make the “true” then just yourself.
Note that Java may have 2 IP address as localhost!
How these differ ???
In any case, we want that from the WiFi, because over the Interent of our data provider via UDP not much will go what we do.
Hope you understand my bad English?
Otherwise just ask again.