All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.loocme.sys.udp.ServerWorker Maven / Gradle / Ivy

There is a newer version: 7.1.11
Show newest version
package com.loocme.sys.udp;

import lombok.extern.slf4j.Slf4j;

import java.net.DatagramPacket;

@Slf4j
public class ServerWorker implements Runnable
{

    private String fromHost;
    private int fromPort;
    private int dataLength = 0;
    private byte[] data;
    private IPackageDeal packageDeal;

    public ServerWorker(DatagramPacket packet, IPackageDeal packageDeal)
    {
        this.fromHost = packet.getAddress().getHostAddress();
        this.fromPort = packet.getPort();
        this.data = packet.getData();
        if (null != this.data)
        {
            this.dataLength = this.data.length;
        }
        this.packageDeal = packageDeal;
    }

    @Override
    public void run()
    {
        log.debug("udp package received, from " + this.fromHost + " : " + this.fromPort + ", data length is " + this.dataLength);
        if (null == this.packageDeal)
        {
            return;
        }

        byte[] resp = packageDeal.execute(this.fromHost, this.fromPort, this.data);
        if (null == resp || 0 == resp.length)
        {
            return;
        }

        SocketClient.send(this.fromHost, this.fromPort, data);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy