好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > SNMP4J服務端連接超時問題解決方案

SNMP4J服務端連接超時問題解決方案

熱門標簽:比較穩定的外呼系統 鸚鵡螺號航海地圖標注時間 信貸電銷機器人系統 云南云電銷機器人招商 山東電信外呼系統靠譜嗎 400 電話 申請費用 江蘇自動外呼系統一般多少錢 ai電話機器人營銷 長沙回撥外呼系統

我們的網絡管理中心作為管理中心,是服務端!各個被管設備通過交換機作為客戶端與網管中心進行通信,使用的TCP/IP協議!

SNMP只是一種協議包,SNMP4J作為SNMP使用的Java工具包,提供了方便安全的工具包功能!

但是在使用中發現一個問題就是,服務端與客戶端發送消息時,發送數次后就不再發送數據了!網絡抓包也抓不到,跟蹤斷點到SNMP4J的代碼中發現了這樣一個問題!

	/**
	 * Sends a SNMP message to the supplied address.
	 * 
	 * @param address
	 *      an <code>TcpAddress</code>. A
	 *      <code>ClassCastException</code> is thrown if
	 *      <code>address</code> is not a <code>TcpAddress</code>
	 *      instance.
	 * @param message
	 *      byte[] the message to sent.
	 * @throws IOException
	 */
	public void sendMessage(Address address, byte[] message)
			throws java.io.IOException {
		if (server == null) {
			listen();
		}
		serverThread.sendMessage(address, message);
	}

我們可以看到,他與UDP的不同是,使用了一個服務的線程!

	public void sendMessage(Address address, byte[] message)
			throws java.io.IOException {
		Socket s = null;
		SocketEntry entry = (SocketEntry) sockets.get(address);
		if (logger.isDebugEnabled()) {
			logger.debug("Looking up connection for destination '"
					+ address + "' returned: " + entry);
			logger.debug(sockets.toString());
		}
		if (entry != null) {
			s = entry.getSocket();
		}
		if ((s == null) || (s.isClosed()) || (!s.isConnected())) {
			if (logger.isDebugEnabled()) {
				logger.debug("Socket for address '" + address
						+ "' is closed, opening it...");
			}
			pending.remove(entry);
			SocketChannel sc = null;
			try {
				// Open the channel, set it to non-blocking, initiate
				// connect
				sc = SocketChannel.open();
				sc.configureBlocking(false);
				sc
						.connect(new InetSocketAddress(
								((TcpAddress) address).getInetAddress(),
								((TcpAddress) address).getPort()));
				s = sc.socket();
				entry = new SocketEntry((TcpAddress) address, s);
				entry.addMessage(message);
				sockets.put(address, entry);
	
				synchronized (pending) {
					pending.add(entry);
				}
	
				selector.wakeup();
				logger.debug("Trying to connect to " + address);
			} catch (IOException iox) {
				logger.error(iox);
				throw iox;
			}
		} else {
			entry.addMessage(message);
			synchronized (pending) {
				pending.add(entry);
			}
			selector.wakeup();
		}
	}

他從一個Map中去獲得連接 SocketEntry ,然后得到連接對象Socket!

判斷Socket是否有效,有效則直接發送,無效則創建連接后再發送!

然后我找到這樣一段代碼

private synchronized void timeoutSocket(SocketEntry entry) { 
  if (connectionTimeout > 0) { 
    socketCleaner.schedule(new SocketTimeout(entry), connectionTimeout); 
  } 
} 

也就是說服務端會自己檢查的連接并且去清除他!

我嘗試設置 connectionTimeout 的值

private void init() throws UnknownHostException, IOException { 
  threadPool = ThreadPool.create("Trap", 2); 
  dispatcher = new MultiThreadedMessageDispatcher(threadPool,new MessageDispatcherImpl()); 
  // 本地IP與監聽端口 
  listenAddress = GenericAddress.parse(System.getProperty("snmp4j.listenAddress", "tcp:192.168.9.69/5055")); 
  DefaultTcpTransportMapping transport; 
  transport = new DefaultTcpTransportMapping((TcpAddress) listenAddress); 
  transport.setConnectionTimeout(0); 
  snmp = new Snmp(dispatcher, transport); 
  snmp.getMessageDispatcher().addMessageProcessingModel(new MPv1()); 
  snmp.getMessageDispatcher().addMessageProcessingModel(new MPv2c()); 
  snmp.getMessageDispatcher().addMessageProcessingModel(new MPv3()); 
  USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0); 
  SecurityModels.getInstance().addSecurityModel(usm); 
  snmp.listen(); 
} 

增加一行代碼 設置DefaultTcpTransportMapping的超時時間是 0 !

然后就沒有問題了!

雖然臨時解決了問題,但是由于對SNMP4J不夠深入了解,我怕問題恐怕不是這樣的!

我在此也希望使用SNMP4J為工具,且作為服務端,在發送數據時有問題的解決方法!

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

標簽:拉薩 運城 齊齊哈爾 衡陽 烏海 嘉興 澳門 亳州

巨人網絡通訊聲明:本文標題《SNMP4J服務端連接超時問題解決方案》,本文關鍵詞  SNMP4J,服務,端,連接,超時,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《SNMP4J服務端連接超時問題解決方案》相關的同類信息!
  • 本頁收集關于SNMP4J服務端連接超時問題解決方案的相關信息資訊供網民參考!
  • 推薦文章