本文整理汇总了Java中java.net.Socket.setPerformancePreferences方法的典型用法代码示例。如果您正苦于以下问题:Java Socket.setPerformancePreferences方法的具体用法?Java Socket.setPerformancePreferences怎么用?Java Socket.setPerformancePreferences使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.Socket
的用法示例。
在下文中一共展示了Socket.setPerformancePreferences方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
示例2: send
import java.net.Socket; //导入方法依赖的package包/类
private synchronized void send(Message message) throws IOException {
if(message == null) return;
Socket socket = new Socket();
socket.setReuseAddress(true);
socket.setPerformancePreferences(2, 1, 0); // connection, latency, bandwidth
socket.setTcpNoDelay(true);
socket.setTrafficClass(0x10); // low delay
socket.setSoTimeout(timeoutMillis);
socket.connect(address);
@SuppressWarnings("resource")
OutputStream out = socket.getOutputStream();
// TODO additional check. Is it needed?
if(out == null) throw new IOException("Socket has no output stream.");
String text = message.toString();
out.write(text.getBytes());
if(CRUSH.debug) CRUSH.debug(this, "DRP> " + text);
out.flush();
socket.close();
}
示例3: 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());
}