List of usage examples for java.net Socket setSendBufferSize
public synchronized void setSendBufferSize(int size) throws SocketException
From source file:Main.java
public static void main(String[] args) throws Exception { Socket client = new Socket("google.com", 80); client.setSendBufferSize(1000); System.out.println(client.getSendBufferSize()); client.close();// w w w.ja va2 s. c om }
From source file:com.smartwork.client.gsocket.CommonSocketFactory.java
public Object makeObject(Object key) throws Exception { ServerAddress address = (ServerAddress) key; Socket conn = new Socket(); conn.setSoTimeout(networkConfig.getReadTimeout() * 1000); conn.setTcpNoDelay(networkConfig.isTcpNoDelay()); conn.setReuseAddress(networkConfig.isReuseAddress()); conn.setSoLinger(networkConfig.getSoLinger() > 0, networkConfig.getSoLinger()); conn.setSendBufferSize(networkConfig.getSendBufferSize()); conn.setReceiveBufferSize(networkConfig.getReceiveBufferSize()); conn.connect(new InetSocketAddress(address.getHost(), address.getPort()), networkConfig.getConnectTimeout() * 1000); return conn;// www . j av a 2 s . co m }
From source file:com.supernovapps.audio.jstreamsourcer.ShoutcastV1.java
public boolean start(Socket sock) { try {/*from www . j a va 2 s.com*/ this.sock = sock; sock.connect(new InetSocketAddress(host, port), 5000); sock.setSendBufferSize(64 * 1024); out = sock.getOutputStream(); PrintWriter output = writeAuthentication(); InputStreamReader isr = new InputStreamReader(sock.getInputStream()); BufferedReader in = new BufferedReader(isr); String line = in.readLine(); if (line == null || !line.contains("OK")) { if (listener != null) { listener.onError("Connection / Authentification error"); } return false; } while (line != null && line.length() > 0) { line = in.readLine(); } writeHeaders(output); } catch (Exception e) { e.printStackTrace(); try { if (sock != null) sock.close(); } catch (IOException e1) { e1.printStackTrace(); } if (listener != null) { listener.onError("Connection / Authentification error"); } return false; } started = true; if (listener != null) { listener.onConnected(); } return true; }
From source file:com.supernovapps.audio.jstreamsourcer.Icecast.java
public boolean start(Socket sock) { try {//ww w . j a v a 2 s .com this.sock = sock; sock.connect(new InetSocketAddress(host, port), timeout); sock.setSendBufferSize(64 * 1024); out = sock.getOutputStream(); PrintWriter output = new PrintWriter(out); output.println("SOURCE " + path + " HTTP/1.0"); writeAuthentication(output); writeHeaders(output); output.println(""); output.flush(); InputStreamReader isr = new InputStreamReader(sock.getInputStream()); BufferedReader in = new BufferedReader(isr); String line = in.readLine(); if (line == null || !line.contains("HTTP") || !line.contains("OK")) { if (listener != null) { listener.onError("Connection / Authentification error"); } return false; } } catch (Exception e) { e.printStackTrace(); try { if (sock != null) { sock.close(); } } catch (IOException e1) { e1.printStackTrace(); } if (listener != null) { listener.onError("Connection / Authentification error"); } return false; } started = true; if (listener != null) { listener.onConnected(); } return true; }
From source file:at.gv.egovernment.moa.id.auth.validator.parep.client.szrgw.SZRGWSecureSocketFactory.java
/** * @see SecureProtocolSocketFactory#createSocket(java.lang.String,int,java.net.InetAddress,int,org.apache.commons.httpclient.params.HttpConnectionParams) *//*w ww .ja v a 2 s . c o m*/ public Socket createSocket(String host, int port, InetAddress clientHost, int clientPort, HttpConnectionParams params) throws IOException, UnknownHostException, org.apache.commons.httpclient.ConnectTimeoutException { Socket socket = createSocket(host, port, clientHost, clientPort); if (socket != null) { // socket.setKeepAlive(false); if (params.getReceiveBufferSize() >= 0) socket.setReceiveBufferSize(params.getReceiveBufferSize()); if (params.getSendBufferSize() >= 0) socket.setSendBufferSize(params.getSendBufferSize()); socket.setReuseAddress(true); if (params.getSoTimeout() >= 0) socket.setSoTimeout(params.getSoTimeout()); } return socket; }
From source file:com.meidusa.venus.io.network.VenusBIOConnectionFactory.java
public VenusBIOConnection makeObject() throws Exception { Socket socket = new Socket(); InetSocketAddress address = null; if (host == null) { address = new InetSocketAddress(port); } else {/* w w w . j a va2 s. com*/ address = new InetSocketAddress(host, port); } socket.setSendBufferSize(sendBufferSize * 1024); socket.setReceiveBufferSize(receiveBufferSize * 1024); socket.setTcpNoDelay(tcpNoDelay); socket.setKeepAlive(keepAlive); try { if (soTimeout > 0) { socket.setSoTimeout(soTimeout); } if (coTimeout > 0) { socket.connect(address, coTimeout); } else { socket.connect(address); } } catch (ConnectException e) { throw new ConnectException(e.getMessage() + " " + address.getHostName() + ":" + address.getPort()); } VenusBIOConnection conn = new VenusBIOConnection(socket, TimeUtil.currentTimeMillis()); byte[] bts = conn.read(); HandshakePacket handshakePacket = new HandshakePacket(); handshakePacket.init(bts); AuthenPacket authen = getAuthenticator().createAuthenPacket(handshakePacket); conn.write(authen.toByteArray()); bts = conn.read(); int type = AbstractServicePacket.getType(bts); if (type == PacketConstant.PACKET_TYPE_OK) { if (authenticatorLogger.isInfoEnabled()) { authenticatorLogger.info("authenticated by server=" + host + ":" + port + " success"); } } else if (type == PacketConstant.PACKET_TYPE_ERROR) { ErrorPacket error = new ErrorPacket(); error.init(bts); if (authenticatorLogger.isInfoEnabled()) { authenticatorLogger.info("authenticated by server=" + host + ":" + port + " error={code=" + error.errorCode + ",message=" + error.message + "}"); } throw new AuthenticationException(error.message, error.errorCode); } return conn; }
From source file:com.lithium.flow.shell.sshj.SshjTunnel.java
private void accept(@Nonnull Socket socket) throws IOException { log.debug("connection from {}", socket.getRemoteSocketAddress()); AbstractDirectChannel channel = new AbstractDirectChannel(connection, "direct-tcpip") { @Override//from w w w . j a v a2 s .com @Nonnull protected SSHPacket buildOpenReq() { return super.buildOpenReq().putString(tunneling.getHost()).putUInt32(tunneling.getPort()) .putString(getHost()).putUInt32(server.getLocalPort()); } }; channel.open(); socket.setSendBufferSize(channel.getLocalMaxPacketSize()); socket.setReceiveBufferSize(channel.getRemoteMaxPacketSize()); Event<IOException> soc2chan = new StreamCopier(socket.getInputStream(), channel.getOutputStream()) .bufSize(channel.getRemoteMaxPacketSize()).spawnDaemon("soc2chan"); Event<IOException> chan2soc = new StreamCopier(channel.getInputStream(), socket.getOutputStream()) .bufSize(channel.getLocalMaxPacketSize()).spawnDaemon("chan2soc"); SocketStreamCopyMonitor.monitor(5, TimeUnit.SECONDS, soc2chan, chan2soc, channel, socket); }
From source file:io.hops.hopsworks.api.util.CustomSSLProtocolSocketFactory.java
@Override public Socket createSocket(String host, int port, InetAddress localAddress, int localPort, HttpConnectionParams httpConnectionParams) throws IOException, UnknownHostException, ConnectTimeoutException { if (httpConnectionParams == null) { LOG.log(Level.SEVERE, "Creating SSL socket but HTTP connection parameters is null"); throw new IllegalArgumentException("HTTP connection parameters cannot be null"); }//from w w w.j a v a2s . co m Socket socket = getSslContext().getSocketFactory().createSocket(); SocketAddress localSocketAddress = new InetSocketAddress(localAddress, localPort); SocketAddress remoteSocketAddress = new InetSocketAddress(host, port); socket.setSoTimeout(httpConnectionParams.getSoTimeout()); if (httpConnectionParams.getLinger() > 0) { socket.setSoLinger(true, httpConnectionParams.getLinger()); } else { socket.setSoLinger(false, 0); } socket.setTcpNoDelay(httpConnectionParams.getTcpNoDelay()); if (httpConnectionParams.getSendBufferSize() >= 0) { socket.setSendBufferSize(httpConnectionParams.getSendBufferSize()); } if (httpConnectionParams.getReceiveBufferSize() >= 0) { socket.setReceiveBufferSize(httpConnectionParams.getReceiveBufferSize()); } socket.bind(localSocketAddress); socket.connect(remoteSocketAddress, httpConnectionParams.getConnectionTimeout()); return socket; }
From source file:com.mirth.connect.connectors.tcp.TcpReceiver.java
private void initSocket(Socket socket) throws SocketException { logger.debug("Initializing socket (" + connectorProperties.getName() + " \"Source\" on channel " + getChannelId() + ")."); socket.setReceiveBufferSize(bufferSize); socket.setSendBufferSize(bufferSize); socket.setSoTimeout(timeout);/*from w ww.ja v a 2 s . co m*/ socket.setKeepAlive(connectorProperties.isKeepConnectionOpen()); socket.setReuseAddress(true); socket.setTcpNoDelay(true); }
From source file:com.mellanox.r4h.DFSOutputStream.java
/** * Create a socket for a write pipeline/*w ww.j av a2s.c o m*/ * * @param first * the first datanode * @param length * the pipeline length * @param client * client * @return the socket connected to the first datanode */ static Socket createSocketForPipeline(final DatanodeInfo first, final int length, final DFSClient client) throws IOException { final String dnAddr = first.getXferAddr(client.getConf().getConnectToDnViaHostname()); if (DFSClient.LOG.isDebugEnabled()) { DFSClient.LOG.debug("Connecting to datanode " + dnAddr); } final InetSocketAddress isa = NetUtils.createSocketAddr(dnAddr); final Socket sock = client.socketFactory.createSocket(); final int timeout = client.getDatanodeReadTimeout(length); NetUtils.connect(sock, isa, client.getRandomLocalInterfaceAddr(), client.getConf().getSocketTimeout()); sock.setSoTimeout(timeout); sock.setSendBufferSize(HdfsConstants.DEFAULT_DATA_SOCKET_SIZE); if (DFSClient.LOG.isDebugEnabled()) { DFSClient.LOG.debug("Send buf size " + sock.getSendBufferSize()); } return sock; }