HI,
I want make UDP server which receives bytes data on data gram socket. My requirement is that UDP server receives byte data continuously and use it for further implementations.
Right now i have done with this requirement in plain java code using threading. The plain java code is working for me. Plain java code of reading data gram packets as per below
Code:while (RunContinuous) { /* Read the Packets */ byte[] buf = new byte[30]; DatagramPacket pack = new DatagramPacket(buf, 30); try (DatagramSocket dgramsock = new DatagramSocket(8080)) { dgramsock.setReceiveBufferSize(30); dgramsock.receive(pack); } dataRecd = pack.getData(); /* OTHER CODE GOES HERE */ }
So for achieve same requirement in spring i am trying spring integration UDP inbound channel adapter.
But its not working for me, Because i must be wrong in implementation.
My spring implementation code:
1. spring-int.xml (Spring integration configuration xml file)
Code:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:task="http://www.springframework.org/schema/task" xmlns:int="http://www.springframework.org/schema/integration" xmlns:int-ip="http://www.springframework.org/schema/integration/ip" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.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="8080"/> <int:service-activator input-channel="channel" ref="objUPDDataReader" method="printTheByetsData"> </int:service-activator> <bean id="objUPDDataReader" class="com.a.b.thread.UDPDataReader"></bean> </beans>
2. UDPDataReader.java (data transformer / print the byte data)
Code:package com.a.b.thread; public class UDPDataReader { public void printTheByetsData(byte[] buffer) { String[] data = new String(buffer).split(","); for (int i = 0; i < data.length; i++) { String strLoopByteData = data[i]; System.out.println("data " + i + " = " + strLoopByteData); } } }
When i run this my SPRING MVC project it's gives me below error
Code:SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 88 in XML document from ServletContext resource [/WEB-INF/spring-int.xml] is invalid; nested exception is org.xml.sax.SAXParseException; systemId: http://www.springframework.org/schema/integration/ip/spring-integration-ip.xsd; lineNumber: 88; columnNumber: 121; src-resolve: Cannot resolve the name 'integration:adviceChainType' to a(n) 'type definition' component.
Please let me correct where things are going wrong.
Your help is appreciable for me.
Regards,
Abhijit


Reply With Quote