本文整理汇总了Java中java.net.Socket.setTrafficClass方法的典型用法代码示例。如果您正苦于以下问题:Java Socket.setTrafficClass方法的具体用法?Java Socket.setTrafficClass怎么用?Java Socket.setTrafficClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.Socket
的用法示例。
在下文中一共展示了Socket.setTrafficClass方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
示例2: 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);
}
}
示例3: 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);
}
}
示例4: 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);
}
}
示例5: process
import java.net.Socket; //导入方法依赖的package包/类
protected void
process(
int local_port,
TransportHelperFilter filter )
{
SocketChannel channel = ((TCPTransportHelper)filter.getHelper()).getSocketChannel();
Socket socket = channel.socket();
//set advanced socket options
try {
int so_sndbuf_size = COConfigurationManager.getIntParameter( "network.tcp.socket.SO_SNDBUF" );
if( so_sndbuf_size > 0 ) socket.setSendBufferSize( so_sndbuf_size );
String ip_tos = COConfigurationManager.getStringParameter( "network.tcp.socket.IPDiffServ" );
if( ip_tos.length() > 0 ) socket.setTrafficClass( Integer.decode( ip_tos ).intValue() );
}
catch( Throwable t ) {
t.printStackTrace();
}
AEProxyAddressMapper.AppliedPortMapping applied_mapping = proxy_address_mapper.applyPortMapping( socket.getInetAddress(), socket.getPort());
InetSocketAddress tcp_address = applied_mapping.getAddress();
ConnectionEndpoint co_ep = new ConnectionEndpoint(tcp_address);
Map<String,Object> properties = applied_mapping.getProperties();
if ( properties != null ){
co_ep.addProperties( properties );
}
ProtocolEndpointTCP pe_tcp = (ProtocolEndpointTCP)ProtocolEndpointFactory.createEndpoint( ProtocolEndpoint.PROTOCOL_TCP, co_ep, tcp_address );
Transport transport = new TCPTransportImpl( pe_tcp, filter );
incoming_manager.addConnection( local_port, filter, transport );
}