com.loocme.sys.util.UdpSocketUtil Maven / Gradle / Ivy
package com.loocme.sys.util;
import com.loocme.sys.udp.IPackageDeal;
import com.loocme.sys.udp.SocketClient;
import com.loocme.sys.udp.SocketServer;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class UdpSocketUtil
{
public static boolean startUdpServer(int port, IPackageDeal packageDeal)
{
return startUdpServer(port, 10, 1024, packageDeal);
}
public static boolean startUdpServer(int port, int packageLength, IPackageDeal packageDeal)
{
return startUdpServer(port, 10, packageLength, packageDeal);
}
public static boolean startUdpServer(int port, int workerNum, int packageLength, IPackageDeal packageDeal)
{
SocketServer udpServer = new SocketServer(port, workerNum, packageLength, packageDeal);
if (udpServer.isInitialSuccess())
{
ThreadUtil.newSingleThreadExecutor().execute(udpServer);
return true;
}
else
{
return false;
}
}
public static void broadcast(int port, byte[] data)
{
SocketClient.broadcast(port, data);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy