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); }
static void set(Socket socket) throws SocketException { socket.setTcpNoDelay(true); socket.setReceiveBufferSize(20000000); socket.setSendBufferSize(10000000); }
public static void setBuffersSizeIfNecessary(SocketChannel socketChannel, int sendBufferSize, int receiveBufferSize) throws IOException { final Socket socket = socketChannel.socket(); if (sendBufferSize > 0) { socket.setSendBufferSize(sendBufferSize); } if (receiveBufferSize > 0) { socket.setReceiveBufferSize(receiveBufferSize); } } }
/** * */ public Socket create(String host, int port) throws Exception { final Socket r = new Socket(host, port); r.setKeepAlive(this.keepAlive); r.setTcpNoDelay(this.tcpNoDelay); if(this.receiveBufferSize > 0) r.setReceiveBufferSize(this.receiveBufferSize); return r; }
newStream.getSocket().setKeepAlive(requireTCPKeepAlive); newStream.getSocket().setReceiveBufferSize(receiveBufferSize); } else { LOGGER.log(Level.WARNING, "Ignore invalid value for receiveBufferSize: {0}", receiveBufferSize); if (sendBufferSize > -1) { if (sendBufferSize > 0) { newStream.getSocket().setSendBufferSize(sendBufferSize); } else { LOGGER.log(Level.WARNING, "Ignore invalid value for sendBufferSize: {0}", sendBufferSize);
socket.setKeepAlive(ENABLE_TCP_KEEP_ALIVE); socket.setReceiveBufferSize(socketBufferSize); socket.setKeepAlive(ENABLE_TCP_KEEP_ALIVE); socket.setReceiveBufferSize(socketBufferSize);
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); } } }
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); }
protected Connection getConnection(SocketAddress dest) throws Exception { Connection conn=connections.get(dest); if(conn != null) return conn; Socket dest_sock=new Socket(); dest_sock.setSendBufferSize(send_buf_size); dest_sock.setReceiveBufferSize(recv_buf_size); dest_sock.connect(dest); Connection c=connections.putIfAbsent(dest, conn=new Connection(dest_sock).start()); if(c != null) { Util.close(conn); return c; } return conn; }
/** * */ public Socket create(String host, int port) throws Exception { final Socket r = new Socket(host, port); r.setKeepAlive(this.keepAlive); r.setTcpNoDelay(this.tcpNoDelay); if(this.receiveBufferSize > 0) r.setReceiveBufferSize(this.receiveBufferSize); return r; }
public static void setupSocket(final Socket sock) throws SocketException { sock.setKeepAlive(true); sock.setReuseAddress(true); sock.setSoTimeout(Constants.READ_TIMEOUT); sock.setSendBufferSize(Math.max(sock.getSendBufferSize(), Constants.BUFFER_LEN * Constants.IO_BUFFERS)); sock.setReceiveBufferSize(Math.max(sock.getReceiveBufferSize(), Constants.BUFFER_LEN * Constants.IO_BUFFERS)); }
import java.net.Socket; public class Main { public static void main(String[] args) { try { Socket socket = new Socket("%%%%.%%%%%.dk", PORT NUMBER); socket.setReceiveBufferSize(2048); socket.setKeepAlive(true); System.out.println("socket " + socket.isConnected()); } catch (Exception e) { System.out.println("error " + e.getMessage()); } } }
public HAConnection(final HAService haService, final SocketChannel socketChannel) throws IOException { this.haService = haService; this.socketChannel = socketChannel; this.clientAddr = this.socketChannel.socket().getRemoteSocketAddress().toString(); this.socketChannel.configureBlocking(false); this.socketChannel.socket().setSoLinger(false, -1); this.socketChannel.socket().setTcpNoDelay(true); this.socketChannel.socket().setReceiveBufferSize(1024 * 64); this.socketChannel.socket().setSendBufferSize(1024 * 64); this.writeSocketService = new WriteSocketService(this.socketChannel); this.readSocketService = new ReadSocketService(this.socketChannel); this.haService.getConnectionCount().incrementAndGet(); }
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); }
public void init(String local_addr, String remote_addr, int local_port, int remote_port) throws Exception { local=new InetSocketAddress(local_addr, local_port); remote=new InetSocketAddress(remote_addr, remote_port); srv_sock=Util.createServerSocket(new DefaultSocketFactory(), "server", local.getAddress(), local.getPort(), local.getPort()); System.out.println("Listening on " + srv_sock.getLocalSocketAddress()); acceptor=new Acceptor(); acceptor.start(); sock=new Socket(); //sock.bind(local); sock.setSendBufferSize(SOCK_SEND_BUF_SIZE); sock.setReceiveBufferSize(SOCK_RECV_BUF_SIZE); try { sock.connect(remote); output=new DataOutputStream(new BufferedOutputStream(sock.getOutputStream())); System.out.println("Connected to " + sock.getRemoteSocketAddress()); } catch(Throwable t) { System.out.println("Failed connecting to " + remote + ": will only act as server"); } }
public OChannelTextServer(final Socket iSocket, final OContextConfiguration iConfiguration) throws IOException { super(iSocket, iConfiguration); socket.setKeepAlive(true); socket.setPerformancePreferences(1, 2, 0); socket.setSendBufferSize(socketBufferSize); socket.setReceiveBufferSize(socketBufferSize); inStream = new BufferedInputStream(socket.getInputStream(), socketBufferSize); outStream = new BufferedOutputStream(socket.getOutputStream(), socketBufferSize); } }
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); } } }
public void run() { while(!srv_sock.isClosed()) { Socket client_sock=null; DataInputStream in=null; try { client_sock=srv_sock.accept(); client_sock.setTcpNoDelay(TCP_NODELAY); client_sock.setReceiveBufferSize(SOCK_RECV_BUF_SIZE); client_sock.setSendBufferSize(SOCK_SEND_BUF_SIZE); in=new DataInputStream(new BufferedInputStream(client_sock.getInputStream())); while(!client_sock.isClosed()) handleRequest(in); } catch(Exception e) { Util.close(client_sock); Util.close(in); } } }
public void run() { try { Socket client_sock=srv_sock.accept(); client_sock.setSendBufferSize(send_buf_size); client_sock.setReceiveBufferSize(recv_buf_size); Connection c; Connection existing=connections.putIfAbsent(client_sock.getRemoteSocketAddress(), c=new Connection(client_sock).start()); if(existing != null) Util.close(c); } catch(Exception e) { throw new RuntimeException(e); } } }
public static SocketChannel connect(SocketAddress remote, final int timeoutMillis) { SocketChannel sc = null; try { sc = SocketChannel.open(); sc.configureBlocking(true); sc.socket().setSoLinger(false, -1); sc.socket().setTcpNoDelay(true); sc.socket().setReceiveBufferSize(1024 * 64); sc.socket().setSendBufferSize(1024 * 64); sc.socket().connect(remote, timeoutMillis); sc.configureBlocking(false); return sc; } catch (Exception e) { if (sc != null) { try { sc.close(); } catch (IOException e1) { e1.printStackTrace(); } } } return null; }