[SNMP4J] Two Snmp, one TransportMapping cause IOException

Frank Fock fock at agentpp.com
Wed Oct 14 21:11:01 CEST 2009


Hi Robert,

This is not an error in the code. If you use a transport
mapping with two Snmp instances (thus also two MessageDispatchers)
then you get a problem with processing a response with
the right MessageDispatcher instance.

Like 
https://server.oosnmp.net/confluence/pages/viewpage.action?pageId=1441794
suggest, you will need to implement your own MessageDispatcher
to avoid redundant processing.

Why are you using two Snmp instances at all?

Regards,
Frank

Robert Mycek wrote:
> Hi,
> 
> asyncMsgProcessingSupported is true by default (AbstractTransportMapping:44)
> 
> Problem is in AbstractTransportMapping.fireProcessMessage(Address,
> ByteBuffer):83
> After first iteration buffer buf is in wrong state (processMessage
> read from buf and change it position)
> I change this line to:
> l.processMessage(this, address, buf.duplicate());
> and after recompilation it works.
> 
> rm
> 
> On Tue, Oct 13, 2009 at 9:47 PM, Frank Fock <fock at agentpp.com> wrote:
>> Hi Robert,
>>
>> Although this is an unusual use case (normally you would use
>> a single Snmp instance with one or more transport mappings),
>> it should work. Prerequisite is that you set
>>
>> transport.setAsyncMsgProcessingSupported(true);
>>
>> before you call
>>
>> transport.listen();
>>
>> Best regards,
>> Frank
>>
>> Robert Mycek wrote:
>>> Hi,
>>>
>>> QUESTION:
>>> Is it OK to put one transportMapping to many Snmp object?
>>>
>>> PROBLEM:
>>> I create 2 Snmp objects and one TransportMapping (UDP).
>>>
>>> TransportMapping transport = new DefaultUdpTransportMapping(address);
>>> transport.listen();
>>> Snmp snmp1 = new Snmp(transport);
>>> Snmp snmp2 = new Snmp(transport);
>>>
>>> Simultaneously in separate threads do request (Set, Get, etc) on snmp1
>>> and snmp2.
>>>
>>> This cause:
>>> java.io.IOException: Unexpected end of input stream at position 87
>>>       at org.snmp4j.asn1.BERInputStream.read(BERInputStream.java:59)
>>>       at org.snmp4j.asn1.BER.decodeHeader(BER.java:578)
>>>       at
>>> org.snmp4j.MessageDispatcherImpl.processMessage(MessageDispatcherImpl.java:327)
>>>       at
>>> org.snmp4j.MessageDispatcherImpl.processMessage(MessageDispatcherImpl.java:309)
>>>       at
>>> org.snmp4j.transport.AbstractTransportMapping.fireProcessMessage(AbstractTransportMapping.java:83)
>>>       at
>>> org.snmp4j.transport.DefaultUdpTransportMapping$ListenThread.run(DefaultUdpTransportMapping.java:364)
>>>       at java.lang.Thread.run(Thread.java:595)
>>>       at
>>> org.snmp4j.util.DefaultThreadFactory$WorkerThread.run(DefaultThreadFactory.java:65)
>>>
>>> snmp4j: 1.10.1
>>>
>>> RM
>>> _______________________________________________
>>> SNMP4J mailing list
>>> SNMP4J at agentpp.org
>>> http://lists.agentpp.org/mailman/listinfo/snmp4j
>> --
>> AGENT++
>> http://www.agentpp.com
>> http://www.snmp4j.com
>> http://www.mibexplorer.com
>> http://www.mibdesigner.com
>>
>>

-- 
AGENT++
http://www.agentpp.com
http://www.snmp4j.com
http://www.mibexplorer.com
http://www.mibdesigner.com




More information about the SNMP4J mailing list