Ewon TechForum
Providing technical solutions to technical requests


UDP Server Example
simon Offline
eWON Support
#1
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);
            }
   }
Reply



Possibly Related Threads…
30-03-2019, 05:02 PM
Last Post: simon
18-02-2019, 04:59 PM
Last Post: simon
23-05-2017, 04:40 PM
Last Post: simon



Users browsing this thread:
1 Guest(s)



Theme © Ewon 2019 - Forum software by © MyBB - Cookie policy