本文整理了Java中java.net.Socket.setTcpNoDelay()
方法的一些代码示例,展示了Socket.setTcpNoDelay()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Socket.setTcpNoDelay()
方法的具体详情如下:
包路径:java.net.Socket
类名称:Socket
方法名:setTcpNoDelay
[英]Sets this socket's SocketOptions#TCP_NODELAY option.
[中]设置此套接字的SocketOptions#TCP_节点延迟选项。
代码示例来源:origin: apache/kafka
private void configureSocketChannel(SocketChannel socketChannel, int sendBufferSize, int receiveBufferSize)
throws IOException {
socketChannel.configureBlocking(false);
Socket socket = socketChannel.socket();
socket.setKeepAlive(true);
if (sendBufferSize != Selectable.USE_DEFAULT_BUFFER_SIZE)
socket.setSendBufferSize(sendBufferSize);
if (receiveBufferSize != Selectable.USE_DEFAULT_BUFFER_SIZE)
socket.setReceiveBufferSize(receiveBufferSize);
socket.setTcpNoDelay(true);
}
代码示例来源:origin: apache/zookeeper
/**
* Helper method to set socket options.
*
* @param sock
* Reference to socket
*/
private void setSockOpts(Socket sock) throws SocketException {
sock.setTcpNoDelay(true);
sock.setKeepAlive(tcpKeepAlive);
sock.setSoTimeout(self.tickTime * self.syncLimit);
}
代码示例来源:origin: apache/flink
private void createConnection() throws IOException {
client = new Socket(hostName, port);
client.setKeepAlive(true);
client.setTcpNoDelay(true);
outputStream = client.getOutputStream();
}
代码示例来源:origin: libgdx/libgdx
public RemoteSender (String ip, int port) {
try {
Socket socket = new Socket(ip, port);
socket.setTcpNoDelay(true);
socket.setSoTimeout(3000);
out = new DataOutputStream(socket.getOutputStream());
out.writeBoolean(Gdx.input.isPeripheralAvailable(Peripheral.MultitouchScreen));
connected = true;
Gdx.input.setInputProcessor(this);
} catch (Exception e) {
Gdx.app.log("RemoteSender", "couldn't connect to " + ip + ":" + port);
}
}
代码示例来源:origin: apache/zookeeper
try {
sock = new Socket(addr.getHostString(), addr.getPort());
sock.setSoLinger(false, -1);
sock.setSoTimeout(1000);
sock.setTcpNoDelay(true);
sock.getOutputStream().write("isro".getBytes());
sock.getOutputStream().flush();
代码示例来源:origin: wildfly/wildfly
static void set(Socket socket) throws SocketException {
socket.setTcpNoDelay(true);
socket.setReceiveBufferSize(20000000);
socket.setSendBufferSize(10000000);
}
代码示例来源:origin: apache/geode
public ServerQueueStatus connect(EndpointManager endpointManager, ServerLocation location,
ClientSideHandshake handshake, int socketBufferSize, int handshakeTimeout, int readTimeout,
CommunicationMode communicationMode, GatewaySender sender, SocketCreator sc)
throws IOException {
theSocket = sc.connectForClient(location.getHostName(), location.getPort(), handshakeTimeout,
socketBufferSize);
theSocket.setTcpNoDelay(true);
theSocket.setSendBufferSize(socketBufferSize);
// Verify buffer sizes
verifySocketBufferSize(socketBufferSize, theSocket.getReceiveBufferSize(), "receive");
verifySocketBufferSize(socketBufferSize, theSocket.getSendBufferSize(), "send");
theSocket.setSoTimeout(handshakeTimeout);
out = theSocket.getOutputStream();
in = theSocket.getInputStream();
this.status = handshake.handshakeWithServer(this, location, communicationMode);
commBuffer = ServerConnection.allocateCommBuffer(socketBufferSize, theSocket);
if (sender != null) {
commBufferForAsyncRead = ServerConnection.allocateCommBuffer(socketBufferSize, theSocket);
}
theSocket.setSoTimeout(readTimeout);
endpoint = endpointManager.referenceEndpoint(location, this.status.getMemberId());
this.connectFinished = true;
this.endpoint.getStats().incConnections(1);
return status;
}
代码示例来源:origin: alibaba/nacos
channel.configureBlocking(false);
channel.socket().setSoLinger(false, -1);
channel.socket().setReuseAddress(true);
channel.socket().setKeepAlive(true);
channel.socket().setTcpNoDelay(true);
代码示例来源:origin: voldemort/voldemort
+ socketChannel.socket().getPort());
socketChannel.socket().setTcpNoDelay(true);
socketChannel.socket().setReuseAddress(true);
socketChannel.socket().setKeepAlive(socketKeepAlive);
socketChannel.socket().setSendBufferSize(socketBufferSize);
代码示例来源:origin: apache/zookeeper
/**
* create a socket channel.
* @return the created socket channel
* @throws IOException
*/
SocketChannel createSock() throws IOException {
SocketChannel sock;
sock = SocketChannel.open();
sock.configureBlocking(false);
sock.socket().setSoLinger(false, -1);
sock.socket().setTcpNoDelay(true);
return sock;
}
代码示例来源:origin: voldemort/voldemort
private void configureSocket(Socket socket) throws SocketException {
socket.setTcpNoDelay(true);
socket.setSendBufferSize(this.socketBufferSize);
if(socket.getReceiveBufferSize() != this.socketBufferSize)
logger.debug("Requested socket receive buffer size was " + this.socketBufferSize
+ " bytes but actual size is " + socket.getReceiveBufferSize() + " bytes.");
if(socket.getSendBufferSize() != this.socketBufferSize)
logger.debug("Requested socket send buffer size was " + this.socketBufferSize
+ " bytes but actual size is " + socket.getSendBufferSize() + " bytes.");
}
代码示例来源:origin: libgdx/libgdx
private void applyHints (SocketHints hints) {
if (hints != null) {
try {
socket.setPerformancePreferences(hints.performancePrefConnectionTime, hints.performancePrefLatency,
hints.performancePrefBandwidth);
socket.setTrafficClass(hints.trafficClass);
socket.setTcpNoDelay(hints.tcpNoDelay);
socket.setKeepAlive(hints.keepAlive);
socket.setSendBufferSize(hints.sendBufferSize);
socket.setReceiveBufferSize(hints.receiveBufferSize);
socket.setSoLinger(hints.linger, hints.lingerDuration);
socket.setSoTimeout(hints.socketTimeout);
} catch (Exception e) {
throw new GdxRuntimeException("Error setting socket hints.", e);
}
}
}
代码示例来源:origin: alibaba/canal
public static BioSocketChannel open(SocketAddress address) throws Exception {
Socket socket = new Socket();
socket.setSoTimeout(BioSocketChannel.SO_TIMEOUT);
socket.setTcpNoDelay(true);
socket.setKeepAlive(true);
socket.setReuseAddress(true);
socket.connect(address, BioSocketChannel.DEFAULT_CONNECT_TIMEOUT);
return new BioSocketChannel(socket);
}
代码示例来源:origin: libgdx/libgdx
public RemoteSender (String ip, int port) {
try {
Socket socket = new Socket(ip, port);
socket.setTcpNoDelay(true);
socket.setSoTimeout(3000);
out = new DataOutputStream(socket.getOutputStream());
out.writeBoolean(Gdx.input.isPeripheralAvailable(Peripheral.MultitouchScreen));
connected = true;
Gdx.input.setInputProcessor(this);
} catch (Exception e) {
Gdx.app.log("RemoteSender", "couldn't connect to " + ip + ":" + port);
}
}
代码示例来源:origin: org.apache.zookeeper/zookeeper
try {
sock = new Socket(addr.getHostName(), addr.getPort());
sock.setSoLinger(false, -1);
sock.setSoTimeout(1000);
sock.setTcpNoDelay(true);
sock.getOutputStream().write("isro".getBytes());
sock.getOutputStream().flush();
代码示例来源:origin: rapidoid/rapidoid
private void configureSocket(SocketChannel socketChannel) throws IOException {
socketChannel.configureBlocking(false);
Socket socket = socketChannel.socket();
socket.setTcpNoDelay(noDelay);
socket.setReceiveBufferSize(bufSize);
socket.setSendBufferSize(bufSize);
socket.setReuseAddress(true);
}
代码示例来源:origin: jenkinsci/jenkins
@Override
public void run() {
try {
// the loop eventually terminates when the socket is closed.
while (!shuttingDown) {
Socket s = serverSocket.accept().socket();
// this prevents a connection from silently terminated by the router in between or the other peer
// and that goes without unnoticed. However, the time out is often very long (for example 2 hours
// by default in Linux) that this alone is enough to prevent that.
s.setKeepAlive(true);
// we take care of buffering on our own
s.setTcpNoDelay(true);
new ConnectionHandler(s, new ConnectionHandlerFailureCallback(this) {
@Override
public void run(Throwable cause) {
LOGGER.log(Level.WARNING, "Connection handler failed, restarting listener", cause);
shutdown();
TcpSlaveAgentListenerRescheduler.schedule(getParentThread(), cause);
}
}).start();
}
} catch (IOException e) {
if(!shuttingDown) {
LOGGER.log(Level.SEVERE,"Failed to accept TCP connections", e);
}
}
}
代码示例来源:origin: org.apache.thrift/libthrift
private TNonblockingSocket(SocketChannel socketChannel, int timeout, SocketAddress socketAddress)
throws IOException {
socketChannel_ = socketChannel;
socketAddress_ = socketAddress;
// make it a nonblocking channel
socketChannel.configureBlocking(false);
// set options
Socket socket = socketChannel.socket();
socket.setSoLinger(false, 0);
socket.setTcpNoDelay(true);
socket.setKeepAlive(true);
setTimeout(timeout);
}
代码示例来源:origin: wildfly/wildfly
socket.setKeepAlive(keepAlive != 0);
socket.setOOBInline(oobInline != 0);
socket.setTcpNoDelay(tcpNoDelay != 0);
final int sendBuffer = this.sendBuffer;
if (sendBuffer > 0) socket.setSendBufferSize(sendBuffer);
final WorkerThread ioThread = worker.getIoThread(hash);
final SelectionKey selectionKey = ioThread.registerChannel(accepted);
代码示例来源:origin: org.apache.zookeeper/zookeeper
/**
* create a socket channel.
* @return the created socket channel
* @throws IOException
*/
SocketChannel createSock() throws IOException {
SocketChannel sock;
sock = SocketChannel.open();
sock.configureBlocking(false);
sock.socket().setSoLinger(false, -1);
sock.socket().setTcpNoDelay(true);
return sock;
}
内容来源于网络,如有侵权,请联系作者删除!