| | |
| | | import java.net.InetAddress; |
| | | import java.net.SocketException; |
| | | import java.net.UnknownHostException; |
| | | import java.util.List; |
| | | import java.util.Vector; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import com.hxzkoa.json.tb_forward_data; |
| | | import com.hxzkoa.json.tb_system; |
| | | import com.hxzkoa.services.SysSettingService; |
| | | |
| | | /** 该类用于UDP转发数据到指定端口地址 */ |
| | | @Component |
| | | public class Udp_Out { |
| | | |
| | | @Autowired |
| | | private SysSettingService sysSettingService; |
| | | public static Udp_Out udpout; |
| | | |
| | | @PostConstruct //关键四:通过@PostConstruct注解实现注入 |
| | | public void init() { |
| | | udpout = this; |
| | | } |
| | | /** |
| | | * 实现UDP转发 |
| | | * |
| | |
| | | DatagramPacket packet=null; |
| | | DatagramSocket socket =null; |
| | | InetAddress address=null; |
| | | int port = 7000; |
| | | List<tb_system> system = udpout.sysSettingService.getSetting(); |
| | | int port = Integer.parseInt(system.get(0).getCs_udp()); |
| | | //String ip = "192.168.31.198"; |
| | | String ip = "127.0.0.1"; |
| | | byte[] data = null; |
| | | try { |