본문 바로가기
IT/Spring

udp-inbound-channel-adapter 이용 was 에 udp server socket 구성

by 최고영회 2013. 12. 24.
728x90
반응형
SMALL

spring3 + myBatis 로 구성한 web server 에서 server socket 을 구성하여 처리해야 하는 경우 

spring 에서 제공하는 udp-inbound-channel-adapter 를 이용하여 처리할 수 있다.

tcp,udp,multicast 등 여러가지 설정값에 따라 사용할 수 있다.

아래 내용은 udp-inbound-channel-adapter 를 이용한 udp server socket 구성 방법

 

servlet-context.xml 

 

 

<?xml version="1.0" encoding="UTF-8"?>

<beans:beans xmlns="http://www.springframework.org/schema/mvc"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:beans="http://www.springframework.org/schema/beans"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:cache="http://www.springframework.org/schema/cache"

xmlns:int="http://www.springframework.org/schema/integration"

    xmlns:int-ip="http://www.springframework.org/schema/integration/ip"

xmlns:xsd="http://www.w3.org/2001/XMLSchema"

xmlns:tool="http://www.springframework.org/schema/tool"

xsi:schemaLocation="http://www.springframework.org/schema/mvc 

http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd

http://www.springframework.org/schema/beans  

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

http://www.springframework.org/schema/context 

http://www.springframework.org/schema/context/spring-context-3.0.xsd

http://www.springframework.org/schema/cache 

http://www.springframework.org/schema/cache/spring-cache.xsd

http://www.springframework.org/schema/integration 

http://www.springframework.org/schema/integration/spring-integration.xsd

    http://www.springframework.org/schema/integration/ip 

http://www.springframework.org/schema/integration/ip/spring-integration-ip.xsd">

.

.

.

.

아래 내용 추가 

 

 

<int:channel id="channel" />

    <int-ip:udp-inbound-channel-adapter id="udpIn" channel="channel" multicast="false" port="1234" so-receive-buffer-size="1024"/>

     <int:service-activator input-channel="channel" ref="udpReceiver" method="receiveByteData">

    </int:service-activator>

        

    <beans:bean id="udpReceiver" class="com.pnpsecure.common.util.UdpReceiver"></beans:bean>

 

 

UdpReceiver Class 정의

public class UdpReceiver{

 

public void receiveByteData(byte[] data) {

try{

ByteArrayInputStream bais = new ByteArrayInputStream(data);

ObjectInputStream ois = new ObjectInputStream(bais);

    Properties prop = (Properties)ois.readObject();  // 객체 직렬화로 properties 객체를 받아 처리

}catch(Exception e)

{

e.printStackTrace();

}

    }

}

 

728x90
반응형
LIST

'IT > Spring' 카테고리의 다른 글

ehcache  (0) 2013.12.24
spring file download  (0) 2013.12.24
Spring2.5 Ajax  (0) 2013.12.24
spring + tiles  (0) 2013.12.24
springMVC + iBatis  (0) 2013.12.24