Best code examples for Java 8 Socket class (java.net.Socket)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Socket class.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

Java 8 Socket examples from Open Source projects
This code example shows how to use the following methods: isBound, isClosed, isConnected, isInputShutdown, isOutputShutdown
147:	if (!socket.isClosed()) { 
-
157:	return socket != null && socket.isBound() && !socket.isClosed() 
158:	&& socket.isConnected() && !socket.isInputShutdown() 
159:	&& !socket.isOutputShutdown(); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: setSoLinger, setSoTimeout, setTcpNoDelay
119:	socket = new Socket(); 
-
121:	socket.setSoLinger(false, 0); 
122:	socket.setTcpNoDelay(true); 
123:	socket.setSoTimeout(timeout); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: connect, setKeepAlive, setReuseAddress, setSoLinger, setTcpNoDelay
24:	final Socket socket = new Socket(); 
-
26:	socket.setReuseAddress(true); 
27:	socket.setKeepAlive(true);  //Will monitor the TCP connection is valid 
28:	socket.setTcpNoDelay(true);  //Socket buffer Whetherclosed, to ensure timely delivery of data 
29:	socket.setSoLinger(true, 0);  //Control calls close () method, the underlying socket is closed immediately 
-
31:	socket.connect(new InetSocketAddress(host, port), timeout); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: close, getChannel, getInetAddress, getInputStream, getLocalAddress
41:	 
42:	public static Peer peerFromSocket(Socket socket) 
43:	throws IOException { 
-
60:	socket.setTcpNoDelay(true); 
61:	SocketChannel channel = socket.getChannel(); 
-
72:	socket.close(); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: getInputStream, getOutputStream
78:	final Socket socket = new Socket(EJBManagementUtil.getNodeName(), 2020); 
79:	final OutputStream sockOut = socket.getOutputStream(); 
80:	final DataInputStream in = new DataInputStream(new TelnetInputStream(socket.getInputStream(), sockOut)); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods:
83:	final Socket socket = metrics ? new ManagedSocketBinding(socketBindings.getUnnamedRegistry()) : new Socket(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods:
63:	Socket socket4 = new Socket(); 
-
70:	when(this.factory.createSocket("test", localhost, 1, localhost, 2)).thenReturn(socket4); 
-
82:	verify(this.manager.getUnnamedRegistry()).registerSocket(socket4); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getChannel, setSoTimeout
121:	s = new Socket(); 
122:	assertNull(s.getChannel()); 
-
127:	NetUtils.connect(s, ss.getLocalSocketAddress(), 1000); 
-
129:	stm = NetUtils.getInputStream(s, 1000); 
-
139:	s.setSoTimeout(1000); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: isClosed
86:	return socket.isClosed(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: bind, connect
65:	return new Socket(proxy); 
-
81:	socket.bind(new InetSocketAddress(localHostAddr, localPort)); 
82:	socket.connect(new InetSocketAddress(addr, port)); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getKeepAlive, getReceiveBufferSize, getReuseAddress, getSendBufferSize, getSoLinger
40:	Socket csock = new Socket(); 
41:	tcpNoDelay = csock.getTcpNoDelay(); 
42:	tcpSendBufferSize = csock.getSendBufferSize(); 
43:	tcpReceiveBufferSize = csock.getReceiveBufferSize(); 
44:	tcpKeepAlive = csock.getKeepAlive(); 
45:	reuseAddress = csock.getReuseAddress(); 
46:	soLinger = csock.getSoLinger(); 
47:	trafficClass = csock.getTrafficClass(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: close, isClosed
49:	if(pSocket != null && !pSocket.isClosed()) { 
-
51:	pSocket.close(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setSoLinger, setSoTimeout, setTcpNoDelay
222:	sock.setTcpNoDelay(HttpConnectionParams.getTcpNoDelay(params)); 
223:	sock.setSoTimeout(HttpConnectionParams.getSoTimeout(params)); 
-
227:	sock.setSoLinger(linger > 0, linger); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: close, getInputStream, getOutputStream
59:	Socket localSocket = new Socket(ADB_HOST, ADB_PORT); 
60:	DataInputStream dis = new DataInputStream(localSocket.getInputStream()); 
61:	OutputStream os = localSocket.getOutputStream(); 
-
72:	localSocket.close(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getInputStream, getOutputStream
405:	out = new PrintStream(socket.getOutputStream(), true); 
-
407:	new BufferedReader(new InputStreamReader(socket.getInputStream(), 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getInetAddress, getLocalAddress, getLocalPort, getPort
31:	String local = socket.getLocalAddress().getHostAddress() + ":" 
32:	+ socket.getLocalPort(); 
33:	String remote = socket.getInetAddress().getHostAddress() + ":" 
34:	+ socket.getPort(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: close
74:	socket.close(); 
-
76:	ROOT_LOGGER.failedToCloseResource(t, socket); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getLocalAddress
220:	socket.getLocalAddress()); 
-
222:	return super.getMtu(socket); // There's no longer an interface with this local address. 
-
227:	return super.getMtu(socket); 
-
230:	return super.getMtu(socket); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: close, connect, setReuseAddress, setSoLinger, setSoTimeout
67:	socket = new Socket( 
-
69:	socket.setReuseAddress(false); 
70:	socket.setSoLinger(false, 1); 
71:	socket.setSoTimeout(timeout); 
72:	socket.connect(socketAddress, timeout); 
-
78:	socket.close(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setSoTimeout
74:	socket.setSoTimeout((int)timeoutMs); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: close, getInputStream, getOutputStream
102:	Socket s = new Socket(host, port); 
-
105:	ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream()); 
106:	ObjectInputStream in = new ObjectInputStream(s.getInputStream()); 
-
124:	s.close(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: connect
54:	Socket s = new Socket(); 
55:	new Killer(s).start(); 
-
58:	s.connect(ss.getLocalSocketAddress()); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getInetAddress, getInputStream, getOutputStream
254:	HttpConnection c = new HttpConnection(this, 
255:	socket.getInetAddress(), 
256:	socket.getInputStream(), 
257:	socket.getOutputStream(), 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getOutputStream
211:	dataOutputStream = dataSocket.getOutputStream(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getInputStream, getOutputStream, getSendBufferSize, setSendBufferSize
37:	_client = new Socket(_host, _port); 
38:	System.out.printf("Socket -> sendBufferSize: %s%n", _client.getSendBufferSize()); 
39:	_client.setSendBufferSize(_client.getSendBufferSize() * 4); 
40:	System.out.printf("Socket -> sendBufferSize: %s%n", _client.getSendBufferSize()); 
41:	_rawo = new DataOutputStream(_client.getOutputStream()); 
42:	_rawi = new DataInputStream(_client.getInputStream()); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: close, isConnected, setReuseAddress, setSoLinger
245:	socket = new Socket(host, port); 
246:	socket.setReuseAddress(true); 
247:	socket.setSoLinger(true, 0); 
248:	boolean isConnected = socket.isConnected(); 
-
267:	socket.close(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: close, getInputStream, getOutputStream, shutdownInput, shutdownOutput
86:	socket = new java.net.Socket(host, port); 
87:	in = socket.getInputStream(); 
88:	out = socket.getOutputStream(); 
-
102:	socket.shutdownInput(); 
103:	socket.shutdownOutput(); 
104:	socket.close(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: connect, setEnabledCipherSuites, setEnabledProtocols, setNeedClientAuth
114:	socket.connect(new InetSocketAddress(address, port), timeout); 
-
116:	socket.setEnabledProtocols(this.jsseSecurityDomain.getProtocols()); 
-
118:	socket.setEnabledCipherSuites(this.jsseSecurityDomain.getCipherSuites()); 
119:	socket.setNeedClientAuth(this.jsseSecurityDomain.isClientAuth()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: close, connect, getInputStream, getOutputStream
46:	socket = new Socket(); 
47:	socket.connect(new InetSocketAddress("127.0.0.1", 
-
50:	out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())); 
51:	in = new BufferedReader(new InputStreamReader(socket.getInputStream())); 
-
69:	socket.close(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getInputStream, getOutputStream
This code example shows how to use the following methods: bind, connect, getChannel, getInetAddress, getLocalAddress
513:	SocketChannel ch = socket.getChannel(); 
-
521:	socket.bind(localAddr); 
-
527:	socket.connect(endpoint, timeout); 
-
541:	if (socket.getLocalPort() == socket.getPort() && 
542:	socket.getLocalAddress().equals(socket.getInetAddress())) { 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: close
147:	socket.close(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: isBound, isClosed, isConnected, isInputShutdown, isOutputShutdown
286:	return (socket.isBound() && 
287:	!socket.isClosed() && socket.isConnected() && 
288:	!socket.isInputShutdown() && !socket.isOutputShutdown()); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods:
70:	this.lockSocket = new Socket(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getOutputStream
186:	OutputStream clientStream = client.getOutputStream(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: close
297:	socket.close(); 
-
299:	ROOT_LOGGER.failedToCloseResource(t, socket); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: bind, connect
129:	socket.connect(destination); 
-
230:	socket.bind(sourceSocketAddress); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: bind, close, connect, setSoLinger
50:	Socket socket = new Socket(); 
-
53:	socket.setSoLinger(true, 0); 
-
55:	socket.bind( 
-
58:	socket.connect( 
-
66:	socket.close(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: close, getInputStream, getOutputStream
47:	final Socket socket = new Socket(InetAddress.getByName(ADDRESS), PORT); 
-
49:	socket.getOutputStream()); 
-
51:	socket.getInputStream()); 
-
59:	socket.close(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: close
61:	socket.close(); 
Full Snippet Info
7
CodeRank
Related Java 8 Socket Questions & Answers:
See Code Examples for Java 8 Socket Methods: