package net.openmob.mobileimsdk.android.utils;

import android.util.Log;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class UDPUtils {
    private static final String TAG = UDPUtils.class.getSimpleName();

    public static boolean send(DatagramSocket skt, byte[] d, int dataLen) {
        if (skt != null && d != null)
            try {
                return send(skt, new DatagramPacket(d, dataLen));
            } catch (Exception e) {
                Log.i(TAG, "发送UDP数据包出错了, remotePort=" + skt
                        .getPort() +"原因:"+ e.getMessage(), e);
                return false;
            }
        Log.e(TAG, ""+ skt);
        return false;
    }

    public static synchronized boolean send(DatagramSocket skt, DatagramPacket p) {
        boolean sendSucess = true;
        if (skt != null && p != null) {
            if (skt.isConnected())
                try {
                    skt.send(p);
                } catch (Exception e) {
                    sendSucess = false;
                    Log.i(TAG, "【IMCORE】send方法中》》无效的参数：skt=" + skt);
                }
        } else {
            Log.i(TAG, "|| p == null!");
        }
        return sendSucess;
    }
}