Java Socket and stream, Java Socket
Zookeeper
ServerSocket and Socket
In the java.net package
Java streams are divided into byte streams and hidden streams.
The top-level abstract classes of byte streams are InputStream and OutputStream.
The top-level abstract classes of the livestream include Reader and Writer.
The Bytes stream class processes Unicode characters, which are double bytes.
Standard input stream
BufferedReader br = new BufferedReader (newInputStreamReader (System. in ))
Needs to be encapsulated as a response stream
Standard output stream
System. out is actually a byte stream.
Streams used for Socket byte processing
Byte stream
BufferedInputStream and BufferedOutputStream
File input and output byte streams
FileInputStream and FileOutputStream
Java socket stream Retrieval
Client code String ip = "localhost ";
String port = pop. getProperty ("8888 );
Socket socket = new Socket (ip, Integer. parseInt (port ));
OutputStream OS = socket. getOutputStream ();
BufferedOutputStream bos = new BufferedOutputStream (OS );
ObjectOutputStream oos = new ObjectOutputStream (bos );
Oos. writeObject (c );
Oos. flush ();
Oos. close ();
Bos. close ();
OS. close ();
Socket. close ();
Server code
ServerSocket server = null;
Socket socket = null;
Server = new ServerSocket ("8888 ");
While (true ){
Socket = server. accept ();
ObjectInputStream ois = new ObjectInputStream (
New BufferedInputStream (socket. getInputStream ()));
Collection <BIDR> collection = (ArrayList) ois. readObject ();
// Perform related operations again
}
Java Socket, one can create multiple IO streams?
Of course not ..
A socket is like a pipe,
Your data is like water flow,
Assume that different data is ink of different colors,
Both black and red go into a pipe,
When it comes out, it cannot be identified.
Du tianwei [authoritative expert]