コード例 #1
0
ファイル: UDP.java プロジェクト: NZDIS/jgroups
  void setBufferSizes() {
    if (sock != null) {
      try {
        sock.setSendBufferSize(ucast_send_buf_size);
      } catch (Throwable ex) {
        Trace.warn("UDP.setBufferSizes()", "failed setting ucast_send_buf_size in sock: " + ex);
      }
      try {
        sock.setReceiveBufferSize(ucast_recv_buf_size);
      } catch (Throwable ex) {
        Trace.warn("UDP.setBufferSizes()", "failed setting ucast_recv_buf_size in sock: " + ex);
      }
    }

    if (mcast_sock != null) {
      try {
        mcast_sock.setSendBufferSize(mcast_send_buf_size);
      } catch (Throwable ex) {
        Trace.warn(
            "UDP.setBufferSizes()", "failed setting mcast_send_buf_size in mcast_sock: " + ex);
      }

      try {
        mcast_sock.setReceiveBufferSize(mcast_recv_buf_size);
      } catch (Throwable ex) {
        Trace.warn(
            "UDP.setBufferSizes()", "failed setting mcast_recv_buf_size in mcast_sock: " + ex);
      }
    }
  }
コード例 #2
0
  /**
   * Activate this <tt>UDPTerminal</tt>.
   *
   * @throws Exception if there is a network failure.
   */
  public synchronized void activate() throws Exception {
    if (!isActive()) {
      if (Modbus.debug)
        CCLog.info(
            "UDPMasterTerminal::activate()::laddr=:" + m_LocalAddress + ":lport=" + m_LocalPort);

      if (m_Socket == null) {
        if (m_LocalAddress != null && m_LocalPort != -1) {
          m_Socket = new DatagramSocket(m_LocalPort, m_LocalAddress);
        } else {
          m_Socket = new DatagramSocket();
          m_LocalPort = m_Socket.getLocalPort();
          m_LocalAddress = m_Socket.getLocalAddress();
        }
      }
      if (Modbus.debug) CCLog.info("UDPMasterTerminal::haveSocket():" + m_Socket.toString());
      if (Modbus.debug)
        CCLog.info(
            "UDPMasterTerminal::laddr=:" + m_LocalAddress.toString() + ":lport=" + m_LocalPort);
      if (Modbus.debug)
        CCLog.info(
            "UDPMasterTerminal::raddr=:" + m_RemoteAddress.toString() + ":rport=" + m_RemotePort);

      m_Socket.setReceiveBufferSize(1024);
      m_Socket.setSendBufferSize(1024);

      m_ModbusTransport = new ModbusUDPTransport(this);
      m_Active = true;
    }
    if (Modbus.debug) CCLog.info("UDPMasterTerminal::activated");
  }
コード例 #3
0
  /**
   * Activate this <tt>UDPTerminal</tt>.
   *
   * @throws Exception if there is a network failure.
   */
  public synchronized void activate() throws Exception {
    if (!isActive()) {
      if (Modbus.debug) System.out.println("UDPSlaveTerminal.activate()");
      if (m_Socket == null) {
        if (m_LocalAddress != null && m_LocalPort != -1) {
          m_Socket = new DatagramSocket(m_LocalPort, m_LocalAddress);
        } else {
          m_Socket = new DatagramSocket();
          m_LocalPort = m_Socket.getLocalPort();
          m_LocalAddress = m_Socket.getLocalAddress();
        }
      }
      if (Modbus.debug) System.out.println("UDPSlaveTerminal::haveSocket():" + m_Socket.toString());
      if (Modbus.debug)
        System.out.println(
            "UDPSlaveTerminal::addr=:" + m_LocalAddress.toString() + ":port=" + m_LocalPort);

      m_Socket.setReceiveBufferSize(1024);
      m_Socket.setSendBufferSize(1024);
      m_PacketReceiver = new PacketReceiver();
      m_Receiver = new Thread(m_PacketReceiver);
      m_Receiver.start();
      if (Modbus.debug) System.out.println("UDPSlaveTerminal::receiver started()");
      m_PacketSender = new PacketSender();
      m_Sender = new Thread(m_PacketSender);
      m_Sender.start();
      if (Modbus.debug) System.out.println("UDPSlaveTerminal::sender started()");
      m_ModbusTransport = new ModbusUDPTransport(this);
      if (Modbus.debug) System.out.println("UDPSlaveTerminal::transport created");
      m_Active = true;
    }
    if (Modbus.debug) System.out.println("UDPSlaveTerminal::activated");
  }
コード例 #4
0
 @Override
 public void setSendBufferSize(int sendBufferSize) {
   try {
     socket.setSendBufferSize(sendBufferSize);
   } catch (SocketException e) {
     throw new ChannelException(e);
   }
 }
コード例 #5
0
 protected void setSocketAttributes(DatagramSocket socket) throws SocketException {
   if (this.getSoTimeout() >= 0) {
     socket.setSoTimeout(this.getSoTimeout());
   }
   if (this.getSoSendBufferSize() > 0) {
     socket.setSendBufferSize(this.getSoSendBufferSize());
   }
 }
コード例 #6
0
ファイル: UdpSocket.java プロジェクト: bkeckes/Dako
  /**
   * Konstruktor
   *
   * @param port UDP-Port, der lokal fuer das Datagramm-Socket verwendet werden soll
   * @param sendBufferSize Groesse des Sendepuffers in Byte
   * @param receiveBufferSize Groesse des Empfangspuffers in Byte
   */
  public UdpSocket(int port, int sendBufferSize, int receiveBufferSize) throws SocketException {
    socket = new DatagramSocket(port);
    try {
      socket.setReceiveBufferSize(receiveBufferSize);
      socket.setSendBufferSize(sendBufferSize);

      System.out.println(
          "Groesse des Empfangspuffers des Datagram-Sockets: "
              + socket.getReceiveBufferSize()
              + " Byte");
      System.out.println(
          "Groesse des Sendepuffers des Datagram-Sockets: " + socket.getSendBufferSize() + " Byte");
    } catch (SocketException e) {
      log.debug("Socketfehler: " + e);
    }
  }
コード例 #7
0
 private void initDatagramSocket() {
   try {
     this.ds = new DatagramSocket(bindaddr);
   } catch (SocketException e) {
     errorHandler.error(
         "Failed to create datagram socket bound to " + bindaddr, e, ErrorCode.GENERIC_FAILURE);
     return;
   }
   if (sendBuffer > 0)
     try {
       ds.setSendBufferSize(sendBuffer);
     } catch (SocketException e) {
       errorHandler.error(
           "Failed to set SO_SNDBUF option to " + sendBuffer + " for datagram socket " + ds,
           e,
           ErrorCode.GENERIC_FAILURE);
     }
 }