[SNMP4J] TCP Port not closed when invoked transport.close method
Frank Fock
fock at agentpp.com
Thu Jul 12 01:35:59 CEST 2007
Hi Vijay,
Depending on your operating system TCP ports may
not immediately be available for reuse. See
http://java.sun.com/j2se/1.5.0/docs/api/java/net/Socket.html#setReuseAddress(boolean)
for an explanation.
To allow immediate reuse, you will have to implement
your own TCPTransportMapping.
I will provide a hookup-method to allow setting socket
options by extending the default mappings.
Best regards,
Frank
Vijay Reddy (dvsreddy) wrote:
> Hi,
>
> Am trying to write SNMP TCP Trap receiver program. Am able to receive
> traps, but when tried to close the connection, still the TCP port is
> listening mode.
>
>
> Can you please let me know if anything wrong in my code as provide
> below, Am working in Eclipse IDE, port is released only when closing the
> Eclipse IDE.
>
>
> private synchronized void listen(IPAddress receiverIp , int
> connectionType, int dest_port ) throws IOException, InterruptedException
> {
>
> String sourceIp = receiverIp.getIPAddress()+ "/"+dest_port;
>
> Snmp snmp = null;
>
> if (connectionType == TrapConstants.TCP) {
>
> transport = new DefaultTcpTransportMapping(new TcpAddress(sourceIp));
>
> } else {
>
> transport = new DefaultUdpTransportMapping(new UdpAddress(sourceIp));
>
> }
>
> ThreadPool threadPool =
>
> ThreadPool.create("DispatcherPool", NUMBER_OF_THREADS);
>
> MessageDispatcher mtDispatcher =
>
> new MultiThreadedMessageDispatcher(threadPool, new
> MessageDispatcherImpl());
>
> mtDispatcher.addMessageProcessingModel(new MPv2c());
>
> snmp = new Snmp(mtDispatcher, transport);
>
> snmp.addCommandResponder(this);
>
> transport.listen();
>
> LogManager.getTextLog().debug("Listening on "+sourceIp);
>
> }
>
> public synchronized void processPdu(CommandResponderEvent event) {
>
> PDU command = event.getPDU();
>
> if (command != null) {
>
> receivedEventList.add(command);
>
> }
>
> }
>
> public void close() throws IOException {
>
> transport.close(); // Call is successfull but doesn't release the
> port immediately.
>
> }
>
>
>
>
> Thanks and regards,
> Vijay
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/snmp4j
--
AGENT++
http://www.agentpp.com
http://www.mibexplorer.com
http://www.mibdesigner.com
More information about the SNMP4J
mailing list