Java Code Examples for java.net.ServerSocket#setReceiveBufferSize()

The following examples show how to use java.net.ServerSocket#setReceiveBufferSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NioServer.java    From TakinRPC with Apache License 2.0 6 votes vote down vote up
private void init() {

        ServerSocketChannel socketChannel = processor.javaChannel();

        ServerSocket javaSocket = socketChannel.socket();

        try {
            if (serverConfig.getReceiveBufferSize() != null) {
                javaSocket.setReceiveBufferSize(serverConfig.getReceiveBufferSize());
            }
            if (serverConfig.getReuseAddress() != null) {
                javaSocket.setReuseAddress(serverConfig.getReuseAddress());
            }
        } catch (SocketException e) {
            throw new NioException("config channel error:" + e.getMessage(), e);
        }
    }
 
Example 2
Source File: Receiver.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Starts up the server. The server that has started accepts and handles TCP requests.
 *
 * @throws IOException if I/O error occurred at startup
 */
public void startup() throws IOException {

   // Create endpoint and inform about starting
   LOG.info("Starting TCP server bound to " + StringUtils.toString(endpoint));

   // Check preconditions
   verifyStartable();

   // Bind sockets
   for (final SelectionKey selectionKey : selector.keys()) {

      // Bind server socket
      try {
         final ServerSocket serverSocket = ((ServerSocketChannel) selectionKey.channel()).socket();
         serverSocket.setReceiveBufferSize(SystemProperty.BUFFER_SIZE);
         serverSocket.setReuseAddress(true);
         serverSocket.bind(endpoint);
      } catch (final BindException e) {
         throw createDetailedBindException(e, endpoint);
      }
   }

   // Start selector thread
   selectorThread.start();
}
 
Example 3
Source File: NioServer.java    From light-task-scheduler with Apache License 2.0 6 votes vote down vote up
private void init() {

        ServerSocketChannel socketChannel = processor.javaChannel();

        ServerSocket javaSocket = socketChannel.socket();

        try {
            if (serverConfig.getReceiveBufferSize() != null) {
                javaSocket.setReceiveBufferSize(serverConfig.getReceiveBufferSize());
            }
            if (serverConfig.getReuseAddress() != null) {
                javaSocket.setReuseAddress(serverConfig.getReuseAddress());
            }
        } catch (SocketException e) {
            throw new NioException("config channel error:" + e.getMessage(), e);
        }
    }
 
Example 4
Source File: DataNode.java    From RDFS with Apache License 2.0 6 votes vote down vote up
private void initDataXceiver(Configuration conf) throws IOException {
  String address = 
    NetUtils.getServerAddress(conf,
                      "dfs.datanode.bindAddress",
                      "dfs.datanode.port",
                      "dfs.datanode.address");
  InetSocketAddress socAddr = NetUtils.createSocketAddr(address);
  // find free port
  ServerSocket ss = (socketWriteTimeout > 0) ? 
        ServerSocketChannel.open().socket() : new ServerSocket();
  Server.bind(ss, socAddr, 
      conf.getInt("dfs.datanode.xceiver.listen.queue.size", 128));
  ss.setReceiveBufferSize(DEFAULT_DATA_SOCKET_SIZE); 
  // adjust machine name with the actual port
  int tmpPort = ss.getLocalPort();
  selfAddr = new InetSocketAddress(ss.getInetAddress().getHostAddress(),
                                   tmpPort);
  LOG.info("Opened info server at " + tmpPort);
    
  this.threadGroup = new ThreadGroup("dataXceiverServer");
  this.dataXceiverServer = new Daemon(threadGroup, 
      new DataXceiverServer(ss, conf, this));
  this.threadGroup.setDaemon(true); // auto destroy when empty
}
 
Example 5
Source File: SocketProperties.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
public void setProperties(ServerSocket socket) throws SocketException{
    if (rxBufSize != null)
        socket.setReceiveBufferSize(rxBufSize.intValue());
    if (performanceConnectionTime != null && performanceLatency != null &&
            performanceBandwidth != null)
        socket.setPerformancePreferences(
                performanceConnectionTime.intValue(),
                performanceLatency.intValue(),
                performanceBandwidth.intValue());
    if (soReuseAddress != null)
        socket.setReuseAddress(soReuseAddress.booleanValue());
    if (soTimeout != null && soTimeout.intValue() >= 0)
        socket.setSoTimeout(soTimeout.intValue());
}
 
Example 6
Source File: SocketProperties.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
public void setProperties(ServerSocket socket) throws SocketException{
    if (rxBufSize != null)
        socket.setReceiveBufferSize(rxBufSize.intValue());
    if (performanceConnectionTime != null && performanceLatency != null &&
            performanceBandwidth != null)
        socket.setPerformancePreferences(
                performanceConnectionTime.intValue(),
                performanceLatency.intValue(),
                performanceBandwidth.intValue());
    if (soReuseAddress != null)
        socket.setReuseAddress(soReuseAddress.booleanValue());
    if (soTimeout != null && soTimeout.intValue() >= 0)
        socket.setSoTimeout(soTimeout.intValue());
}
 
Example 7
Source File: WriteTimelyPluginTest.java    From timely with Apache License 2.0 5 votes vote down vote up
public void create() throws Exception {
    server = new ServerSocket(port);
    server.setReceiveBufferSize(8192);
    host = server.getInetAddress().getHostAddress();
    port = server.getLocalPort();
    System.out.println("Local port " + port);
}
 
Example 8
Source File: PortRange.java    From drftpd with GNU General Public License v2.0 5 votes vote down vote up
private ServerSocket createServerSocket(int port, ServerSocketFactory ssf, String bindIP) throws IOException {
    ServerSocket ss = ssf.createServerSocket();
    if (_bufferSize > 0) {
        ss.setReceiveBufferSize(_bufferSize);
    }
    if (bindIP == null) {
        ss.bind(new InetSocketAddress(port), 1);
    } else {
        ss.bind(new InetSocketAddress(bindIP, port), 1);
    }
    return ss;
}
 
Example 9
Source File: SocketProperties.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
public void setProperties(ServerSocket socket) throws SocketException{
    if (rxBufSize != null)
        socket.setReceiveBufferSize(rxBufSize.intValue());
    if (performanceConnectionTime != null && performanceLatency != null &&
            performanceBandwidth != null)
        socket.setPerformancePreferences(
                performanceConnectionTime.intValue(),
                performanceLatency.intValue(),
                performanceBandwidth.intValue());
    if (soReuseAddress != null)
        socket.setReuseAddress(soReuseAddress.booleanValue());
    if (soTimeout != null && soTimeout.intValue() >= 0)
        socket.setSoTimeout(soTimeout.intValue());
}
 
Example 10
Source File: PortRange.java    From drftpd with GNU General Public License v2.0 5 votes vote down vote up
private ServerSocket createServerSocket(int port, ServerSocketFactory ssf, String bindIP) throws IOException {
    ServerSocket ss = ssf.createServerSocket();
    if (_bufferSize > 0) {
        ss.setReceiveBufferSize(_bufferSize);
    }
    if (bindIP == null) {
        ss.bind(new InetSocketAddress(port), 1);
    } else {
        ss.bind(new InetSocketAddress(bindIP, port), 1);
    }
    return ss;
}
 
Example 11
Source File: RapidoidServerLoop.java    From rapidoid with Apache License 2.0 3 votes vote down vote up
private void openSocket() throws IOException {
	U.notNull(net.protocol(), "protocol");
	U.notNull(net.helperClass(), "helperClass");

	String blockingInfo = net.blockingAccept() ? "blocking" : "non-blocking";
	Log.debug("Initializing server", "address", net.address(), "port", net.port(), "sync", net.syncBufs(), "accept", blockingInfo);

	serverSocketChannel = ServerSocketChannel.open();

	if ((serverSocketChannel.isOpen()) && (selector.isOpen())) {

		serverSocketChannel.configureBlocking(net.blockingAccept());

		ServerSocket socket = serverSocketChannel.socket();

		Log.info("!Starting server", "!address", net.address(), "!port", net.port(), "I/O workers", net.workers(), "sync", net.syncBufs(), "accept", blockingInfo);

		InetSocketAddress addr = new InetSocketAddress(net.address(), net.port());

		socket.setReceiveBufferSize(16 * 1024);
		socket.setReuseAddress(true);
		socket.bind(addr, MAX_PENDING_CONNECTIONS);

		Log.debug("Opened server socket", "address", addr);

		if (!net.blockingAccept()) {
			Log.debug("Registering accept selector");
			serverSocketChannel.register(selector, SelectionKey.OP_ACCEPT);
		}

		initWorkers();

	} else {
		throw U.rte("Cannot open socket!");
	}
}