package cn.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.ip.udp.UnicastSendingMessageHandler;

import cn.component.message.udp.GroupServer;

import java.net.InetSocketAddress;

/**
 * UDP配置类
 */
@Configuration
public class UdpConfig {

    @Value("${sam.udp.groupAddress}")
    private String groupAddress;

    @Value("${sam.udp.groupPort}")
    private int groupPort;

    @Bean
    public GroupServer getGroupServer() {
        GroupServer groupServer = new GroupServer();
        groupServer.start(new InetSocketAddress(groupAddress, groupPort));
        return groupServer;
    }

    @Bean
    public UnicastSendingMessageHandler unicastSendingMessageHandler() {
        return new UnicastSendingMessageHandler(groupAddress, groupPort);
    }

}
