package org.hongxi.java.net;

import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

/**
 * Created by javahongxi on 2018/1/2.
 */
public class UDPServer {
	public static void main(String[] args) {
		try {
			byte[] buf = new byte[1024];
			DatagramPacket dp = new DatagramPacket(buf, buf.length);
			DatagramSocket ds = new DatagramSocket(5678);
			while (true) {
				ds.receive(dp);
				ByteArrayInputStream bais = new ByteArrayInputStream(buf);
				DataInputStream dis = new DataInputStream(bais);
				System.out.println(dis.readLong());
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
