
package org.geotools.GpsSim;



import java.io.*;
import java.net.*;
import java.util.*;

public class udpListener {
    public static void main(String[] args) throws IOException {

		DatagramSocket gpssocket = new DatagramSocket(5400);
		DatagramSocket accsocket = new DatagramSocket(5401);

		byte[] buf1 = new byte[256];
                byte[] buf2 = new byte[256];

		while(true){
			DatagramPacket packet1 = new DatagramPacket(buf1, buf1.length);
                        DatagramPacket packet2 = new DatagramPacket(buf2, buf2.length);
			gpssocket.receive(packet1);
                        accsocket.receive(packet2);
			String receivedgps = new String(packet1.getData(), 0, packet1.getLength());
                        String receivedacc = new String(packet2.getData(), 0, packet2.getLength());
			System.out.println(receivedgps+" | "+receivedacc);
                        String[] gps = receivedgps.split("\\|");
                        String[] acc = receivedacc.split("\\|");
                        if(Double.parseDouble(acc[0])>40 || Double.parseDouble(acc[1])>40 ||
                                Double.parseDouble(acc[0])<-40 || Double.parseDouble(acc[1])<-40){
                            System.out.println("Devrilen tren: "+gps[0]);


                        }

		}
    }
}
