當前位置: 首頁>>代碼示例>>Java>>正文


Java Socket.setReceiveBufferSize方法代碼示例

本文整理匯總了Java中java.net.Socket.setReceiveBufferSize方法的典型用法代碼示例。如果您正苦於以下問題:Java Socket.setReceiveBufferSize方法的具體用法?Java Socket.setReceiveBufferSize怎麽用?Java Socket.setReceiveBufferSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.net.Socket的用法示例。


在下文中一共展示了Socket.setReceiveBufferSize方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: run

import java.net.Socket; //導入方法依賴的package包/類
public void run() {
    try {
        while (!socket.isClosed()) {
            pause.get().await();
            try {
                Socket source = socket.accept();
                pause.get().await();
                if (receiveBufferSize > 0) {
                    source.setReceiveBufferSize(receiveBufferSize);
                }
                LOG.info("accepted " + source + ", receiveBufferSize:" + source.getReceiveBufferSize());
                synchronized (connections) {
                    connections.add(new Bridge(source, target));
                }
            } catch (SocketTimeoutException expected) {
            }
        }
    } catch (Exception e) {
        LOG.debug("acceptor: finished for reason: " + e.getLocalizedMessage());
    }
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:22,代碼來源:SocketProxy.java

示例2: run

import java.net.Socket; //導入方法依賴的package包/類
@Override
public void run() {
          try {
              while (!socket.isClosed()) {
                  pause.get().await();
                  try {
                      Socket source = socket.accept();
                      pause.get().await();
                      if (receiveBufferSize > 0) {
                          source.setReceiveBufferSize(receiveBufferSize);
                      }
                      LOG.info("accepted " + source + ", receiveBufferSize:" + source.getReceiveBufferSize());
                      synchronized (connections) {
                          connections.add(new Bridge(source, target));
                      }
                  } catch (SocketTimeoutException expected) {
                  }
              }
          } catch (Exception e) {
              LOG.debug("acceptor: finished for reason: " + e.getLocalizedMessage());
          }
      }
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:23,代碼來源:SocketProxy.java

示例3: configure

import java.net.Socket; //導入方法依賴的package包/類
@Override
public void configure(final Socket socket) throws IOException {
    if(preferences.getInteger("connection.buffer.receive") > 0) {
        socket.setReceiveBufferSize(preferences.getInteger("connection.buffer.receive"));
    }
    if(preferences.getInteger("connection.buffer.send") > 0) {
        socket.setSendBufferSize(preferences.getInteger("connection.buffer.send"));
    }
    final int timeout = preferences.getInteger("connection.timeout.seconds") * 1000;
    if(log.isInfoEnabled()) {
        log.info(String.format("Set timeout to %dms for socket %s", timeout, socket));
    }
    socket.setSoTimeout(timeout);
    if(preferences.getBoolean("connection.socket.linger")) {
        // The setting only affects socket close. Make sure closing SSL socket does not hang because close_notify cannot be sent.
        socket.setSoLinger(true, timeout);
    }
    if(preferences.getBoolean("connection.socket.keepalive")) {
        socket.setKeepAlive(true);
    }
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:22,代碼來源:DefaultSocketConfigurator.java

示例4: setProperties

import java.net.Socket; //導入方法依賴的package包/類
public void setProperties(Socket socket) throws SocketException{
    if (rxBufSize != null)
        socket.setReceiveBufferSize(rxBufSize.intValue());
    if (txBufSize != null)
        socket.setSendBufferSize(txBufSize.intValue());
    if (ooBInline !=null)
        socket.setOOBInline(ooBInline.booleanValue());
    if (soKeepAlive != null)
        socket.setKeepAlive(soKeepAlive.booleanValue());
    if (performanceConnectionTime != null && performanceLatency != null &&
            performanceBandwidth != null)
        socket.setPerformancePreferences(
                performanceConnectionTime.intValue(),
                performanceLatency.intValue(),
                performanceBandwidth.intValue());
    if (soReuseAddress != null)
        socket.setReuseAddress(soReuseAddress.booleanValue());
    if (soLingerOn != null && soLingerTime != null)
        socket.setSoLinger(soLingerOn.booleanValue(),
                soLingerTime.intValue());
    if (soTimeout != null && soTimeout.intValue() >= 0)
        socket.setSoTimeout(soTimeout.intValue());
    if (tcpNoDelay != null)
        socket.setTcpNoDelay(tcpNoDelay.booleanValue());
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:26,代碼來源:SocketProperties.java

示例5: SetReceiveBufferSize

import java.net.Socket; //導入方法依賴的package包/類
public SetReceiveBufferSize() throws Exception {
    ServerSocket ss = new ServerSocket(0);
    Socket s = new Socket("localhost", ss.getLocalPort());
    Socket accepted = ss.accept();
    try {
        s.setReceiveBufferSize(0);
    } catch (IllegalArgumentException e) {
        return;
    } catch (Exception ex) {
    } finally {
        ss.close();
        s.close();
        accepted.close();
    }
    throw new RuntimeException("IllegalArgumentException not thrown!");
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:17,代碼來源:SetReceiveBufferSize.java

示例6: run

import java.net.Socket; //導入方法依賴的package包/類
@Override
public void run() {
    try {
        while (!isTerminated() && !Thread.interrupted()) {
            final Socket socket = this.serversocket.accept();
            socket.setSoTimeout(this.socketConfig.getSoTimeout());
            socket.setKeepAlive(this.socketConfig.isSoKeepAlive());
            socket.setTcpNoDelay(this.socketConfig.isTcpNoDelay());
            if (this.socketConfig.getRcvBufSize() > 0) {
                socket.setReceiveBufferSize(this.socketConfig.getRcvBufSize());
            }
            if (this.socketConfig.getSndBufSize() > 0) {
                socket.setSendBufferSize(this.socketConfig.getSndBufSize());
            }
            if (this.socketConfig.getSoLinger() >= 0) {
                socket.setSoLinger(true, this.socketConfig.getSoLinger());
            }
            final HttpServerConnection conn = this.connectionFactory.createConnection(socket);
            final Worker worker = new Worker(this.httpService, conn, this.exceptionLogger);
            this.executorService.execute(worker);
        }
    } catch (final Exception ex) {
        this.exceptionLogger.log(ex);
    }
}
 
開發者ID:gusavila92,項目名稱:java-android-websocket-client,代碼行數:26,代碼來源:RequestListener.java

示例7: NodeReceiveThread

import java.net.Socket; //導入方法依賴的package包/類
public NodeReceiveThread(Socket sk) {
		super();
		this.sk = sk;
		try {
			sk.setSendBufferSize(1024*1024);
			sk.setReceiveBufferSize(1024*1024);
			out = new ObjectOutputStream(sk.getOutputStream());
			in = new ObjectInputStream(sk.getInputStream());
		} catch (IOException e) {
			// TODO Auto-generated catch block
e.printStackTrace();logger.error("Exception",e);
		}
	}
 
開發者ID:zrtzrt,項目名稱:CrawlerSYS,代碼行數:14,代碼來源:NodeReceiveThread.java

示例8: configureSocket

import java.net.Socket; //導入方法依賴的package包/類
private void configureSocket(Socket socket) throws SocketException {
    socket.setTcpNoDelay(TCP_NO_DELAY.get(settings));
    ByteSizeValue tcpSendBufferSize = TCP_SEND_BUFFER_SIZE.get(settings);
    if (tcpSendBufferSize.getBytes() > 0) {
        socket.setSendBufferSize(tcpSendBufferSize.bytesAsInt());
    }
    ByteSizeValue tcpReceiveBufferSize = TCP_RECEIVE_BUFFER_SIZE.get(settings);
    if (tcpReceiveBufferSize.getBytes() > 0) {
        socket.setReceiveBufferSize(tcpReceiveBufferSize.bytesAsInt());
    }
    socket.setReuseAddress(TCP_REUSE_ADDRESS.get(settings));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:13,代碼來源:MockTcpTransport.java

示例9: listen

import java.net.Socket; //導入方法依賴的package包/類
public void listen() throws Exception {
    if (doListen()) {
        log.warn("ServerSocket already started");
        return;
    }
    setListen(true);

    while ( doListen() ) {
        Socket socket = null;
        if ( getTaskPool().available() < 1 ) {
            if ( log.isWarnEnabled() )
                log.warn("All BIO server replication threads are busy, unable to handle more requests until a thread is freed up.");
        }
        BioReplicationTask task = (BioReplicationTask)getTaskPool().getRxTask();
        if ( task == null ) continue; //should never happen
        try {
            socket = serverSocket.accept();
        }catch ( Exception x ) {
            if ( doListen() ) throw x;
        }
        if ( !doListen() ) {
            task.setDoRun(false);
            task.serviceSocket(null,null);
            getExecutor().execute(task);
            break; //regular shutdown
        }
        if ( socket == null ) continue;
        socket.setReceiveBufferSize(getRxBufSize());
        socket.setSendBufferSize(getTxBufSize());
        socket.setTcpNoDelay(getTcpNoDelay());
        socket.setKeepAlive(getSoKeepAlive());
        socket.setOOBInline(getOoBInline());
        socket.setReuseAddress(getSoReuseAddress());
        socket.setSoLinger(getSoLingerOn(),getSoLingerTime());
        socket.setSoTimeout(getTimeout());
        ObjectReader reader = new ObjectReader(socket);
        task.serviceSocket(socket,reader);
        getExecutor().execute(task);
    }//while
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:41,代碼來源:BioReceiver.java

示例10: openSocket

import java.net.Socket; //導入方法依賴的package包/類
/**
 * open real socket and set time out when waitForAck is enabled
 * is socket open return directly
 */
protected void openSocket() throws IOException {
   if(isConnected()) return ;
   try {
       socket = new Socket();
       InetSocketAddress sockaddr = new InetSocketAddress(getAddress(), getPort());
       socket.connect(sockaddr,(int)getTimeout());
       socket.setSendBufferSize(getTxBufSize());
       socket.setReceiveBufferSize(getRxBufSize());
       socket.setSoTimeout( (int) getTimeout());
       socket.setTcpNoDelay(getTcpNoDelay());
       socket.setKeepAlive(getSoKeepAlive());
       socket.setReuseAddress(getSoReuseAddress());
       socket.setOOBInline(getOoBInline());
       socket.setSoLinger(getSoLingerOn(),getSoLingerTime());
       socket.setTrafficClass(getSoTrafficClass());
       setConnected(true);
       soOut = socket.getOutputStream();
       soIn  = socket.getInputStream();
       setRequestCount(0);
       setConnectTime(System.currentTimeMillis());
       if (log.isDebugEnabled())
           log.debug(sm.getString("IDataSender.openSocket", getAddress().getHostAddress(), Integer.valueOf(getPort()), Long.valueOf(0)));
  } catch (IOException ex1) {
      SenderState.getSenderState(getDestination()).setSuspect();
      if (log.isDebugEnabled())
          log.debug(sm.getString("IDataSender.openSocket.failure",getAddress().getHostAddress(), Integer.valueOf(getPort()), Long.valueOf(0)), ex1);
      throw (ex1);
    }
    
 }
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:35,代碼來源:BioSender.java

示例11: openSocket

import java.net.Socket; //導入方法依賴的package包/類
/**
 * open real socket and set time out when waitForAck is enabled is socket
 * open return directly
 */
protected void openSocket() throws IOException {
	if (isConnected())
		return;
	try {
		socket = new Socket();
		InetSocketAddress sockaddr = new InetSocketAddress(getAddress(), getPort());
		socket.connect(sockaddr, (int) getTimeout());
		socket.setSendBufferSize(getTxBufSize());
		socket.setReceiveBufferSize(getRxBufSize());
		socket.setSoTimeout((int) getTimeout());
		socket.setTcpNoDelay(getTcpNoDelay());
		socket.setKeepAlive(getSoKeepAlive());
		socket.setReuseAddress(getSoReuseAddress());
		socket.setOOBInline(getOoBInline());
		socket.setSoLinger(getSoLingerOn(), getSoLingerTime());
		socket.setTrafficClass(getSoTrafficClass());
		setConnected(true);
		soOut = socket.getOutputStream();
		soIn = socket.getInputStream();
		setRequestCount(0);
		setConnectTime(System.currentTimeMillis());
		if (log.isDebugEnabled())
			log.debug(sm.getString("IDataSender.openSocket", getAddress().getHostAddress(),
					Integer.valueOf(getPort()), Long.valueOf(0)));
	} catch (IOException ex1) {
		SenderState.getSenderState(getDestination()).setSuspect();
		if (log.isDebugEnabled())
			log.debug(sm.getString("IDataSender.openSocket.failure", getAddress().getHostAddress(),
					Integer.valueOf(getPort()), Long.valueOf(0)), ex1);
		throw (ex1);
	}

}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:38,代碼來源:BioSender.java

示例12: configureSocket

import java.net.Socket; //導入方法依賴的package包/類
/**
 * Configures socket properties based on properties from the connection
 * (tcpNoDelay, snd/rcv buf, traffic class, etc).
 * 
 * @param props
 * @throws SocketException
 * @throws IOException
 */
private void configureSocket(Socket sock, Properties props) throws SocketException, IOException {
    sock.setTcpNoDelay(Boolean.valueOf(props.getProperty(TCP_NO_DELAY_PROPERTY_NAME, TCP_NO_DELAY_DEFAULT_VALUE)).booleanValue());

    String keepAlive = props.getProperty(TCP_KEEP_ALIVE_PROPERTY_NAME, TCP_KEEP_ALIVE_DEFAULT_VALUE);

    if (keepAlive != null && keepAlive.length() > 0) {
        sock.setKeepAlive(Boolean.valueOf(keepAlive).booleanValue());
    }

    int receiveBufferSize = Integer.parseInt(props.getProperty(TCP_RCV_BUF_PROPERTY_NAME, TCP_RCV_BUF_DEFAULT_VALUE));

    if (receiveBufferSize > 0) {
        sock.setReceiveBufferSize(receiveBufferSize);
    }

    int sendBufferSize = Integer.parseInt(props.getProperty(TCP_SND_BUF_PROPERTY_NAME, TCP_SND_BUF_DEFAULT_VALUE));

    if (sendBufferSize > 0) {
        sock.setSendBufferSize(sendBufferSize);
    }

    int trafficClass = Integer.parseInt(props.getProperty(TCP_TRAFFIC_CLASS_PROPERTY_NAME, TCP_TRAFFIC_CLASS_DEFAULT_VALUE));

    if (trafficClass > 0) {
        sock.setTrafficClass(trafficClass);
    }
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:36,代碼來源:StandardSocketFactory.java

示例13: create

import java.net.Socket; //導入方法依賴的package包/類
@Override
public HttpClientConnection create(final HttpHost host) throws IOException {
    final String scheme = host.getSchemeName();
    Socket socket = null;
    if ("http".equalsIgnoreCase(scheme)) {
        socket = this.plainfactory != null ? this.plainfactory.createSocket() :
                new Socket();
    } if ("https".equalsIgnoreCase(scheme)) {
        socket = (this.sslfactory != null ? this.sslfactory :
                SSLSocketFactory.getDefault()).createSocket();
    }
    if (socket == null) {
        throw new IOException(scheme + " scheme is not supported");
    }
    final String hostname = host.getHostName();
    int port = host.getPort();
    if (port == -1) {
        if (host.getSchemeName().equalsIgnoreCase("http")) {
            port = 80;
        } else if (host.getSchemeName().equalsIgnoreCase("https")) {
            port = 443;
        }
    }
    socket.setSoTimeout(this.sconfig.getSoTimeout());
    if (this.sconfig.getSndBufSize() > 0) {
        socket.setSendBufferSize(this.sconfig.getSndBufSize());
    }
    if (this.sconfig.getRcvBufSize() > 0) {
        socket.setReceiveBufferSize(this.sconfig.getRcvBufSize());
    }
    socket.setTcpNoDelay(this.sconfig.isTcpNoDelay());
    final int linger = this.sconfig.getSoLinger();
    if (linger >= 0) {
        socket.setSoLinger(true, linger);
    }
    socket.setKeepAlive(this.sconfig.isSoKeepAlive());
    socket.connect(new InetSocketAddress(hostname, port), this.connectTimeout);
    return this.connFactory.createConnection(socket);
}
 
開發者ID:gusavila92,項目名稱:java-android-websocket-client,代碼行數:40,代碼來源:BasicConnFactory.java

示例14: listen

import java.net.Socket; //導入方法依賴的package包/類
public void listen() throws Exception {
	if (doListen()) {
		log.warn("ServerSocket already started");
		return;
	}
	setListen(true);

	while (doListen()) {
		Socket socket = null;
		if (getTaskPool().available() < 1) {
			if (log.isWarnEnabled())
				log.warn(
						"All BIO server replication threads are busy, unable to handle more requests until a thread is freed up.");
		}
		BioReplicationTask task = (BioReplicationTask) getTaskPool().getRxTask();
		if (task == null)
			continue; // should never happen
		try {
			socket = serverSocket.accept();
		} catch (Exception x) {
			if (doListen())
				throw x;
		}
		if (!doListen()) {
			task.setDoRun(false);
			task.serviceSocket(null, null);
			getExecutor().execute(task);
			break; // regular shutdown
		}
		if (socket == null)
			continue;
		socket.setReceiveBufferSize(getRxBufSize());
		socket.setSendBufferSize(getTxBufSize());
		socket.setTcpNoDelay(getTcpNoDelay());
		socket.setKeepAlive(getSoKeepAlive());
		socket.setOOBInline(getOoBInline());
		socket.setReuseAddress(getSoReuseAddress());
		socket.setSoLinger(getSoLingerOn(), getSoLingerTime());
		socket.setSoTimeout(getTimeout());
		ObjectReader reader = new ObjectReader(socket);
		task.serviceSocket(socket, reader);
		getExecutor().execute(task);
	} // while
}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:45,代碼來源:BioReceiver.java


注:本文中的java.net.Socket.setReceiveBufferSize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。