UDP Server Example - simon - 25-06-2020
Hi Guys,
Here is a little example of a UDP Echo Server running on Flexy (Firmware > 12.2 - using J2SE)
Code: public static void main(String[] args) throws Exception {
DatagramSocket serverSocket = new DatagramSocket(9876);
byte[] receiveData = new byte[1024];
byte[] sendData = new byte[1024];
System.out.println("UDP Server started");
while(true)
{
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
serverSocket.receive(receivePacket);
String sentence = new String( receivePacket.getData());
System.out.println("RECEIVED: " + sentence);
InetAddress IPAddress = receivePacket.getAddress();
int port = receivePacket.getPort();
String capitalizedSentence = sentence.toUpperCase();
sendData = capitalizedSentence.getBytes();
DatagramPacket sendPacket =
new DatagramPacket(sendData, sendData.length, IPAddress, port);
serverSocket.send(sendPacket);
}
}
RE: UDP Server Example - HarmGroth - 23-11-2020
This thread has been marked as solved. If you have a similar issue, it would be better to post your own thread rather than bump this one, to help keep everybody's different issues separate.
(25-06-2020, 04:15 PM)simon Wrote: Hi Guys,
Here is a little example of a UDP Echo Server running on Flexy (Firmware > 12.2 - using J2SE)
Code: public static void main(String[] args) throws Exception {
DatagramSocket serverSocket = new DatagramSocket(9876);
byte[] receiveData = new byte[1024];
byte[] sendData = new byte[1024];
System.out.println("UDP Server started");
while(true)
{
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
serverSocket.receive(receivePacket);
String sentence = new String( receivePacket.getData());
System.out.println("RECEIVED: " + sentence);
InetAddress IPAddress = receivePacket.getAddress();
int port = receivePacket.getPort();
String capitalizedSentence = sentence.toUpperCase();
sendData = capitalizedSentence.getBytes();
DatagramPacket sendPacket =
new DatagramPacket(sendData, sendData.length, IPAddress, port);
serverSocket.send(sendPacket);
}
}
Simon,
I tried to find any information on this in the Ewon toolkit documentation and it doesn't come up anywhere.
Is this something that is planned for future release or in a toolkit that hasn't been released?
Some clarification would be great.
Thank you very much
Best regards,
Harm
RE: UDP Server Example - simon - 24-11-2020
Hi Harm,
No, nothing planned so far for a new release.
What information are you looking for ? Everything is on https://developer.ewon.biz/content/java-0
Simon
|