/*
It can be run in the main method, or it can be put into a thread, preferably in a thread.
With the previous write operation can be taken directly to see the effect of running
*/
BufferedReader br = null; Read Stream operations
try {
br = new BufferedReader (New InputStreamReader (Sk.getinputstream ())); Docking of three channels
String str = br.readline (); Use a string to receive
String [] str1 = Str.split ("&"); Splits the received message into a few segments and puts it into the array
Date Sendtime = new Date (Long.parselong (str1[2)); Get current time
SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); Set the time format
System.out.println (Sdf.format (sendtime)); Show time
SYSTEM.OUT.PRINTLN (str1[0]+ "said:" + "\ n" +str1[1]); Displays messages sent by the write operation side
} catch (IOException e) {
TODO Auto-generated catch block
E.printstacktrace ();
}finally{
if (br!=null) {
try {
Br.close (); Close the stream
} catch (IOException e) {
TODO Auto-generated catch block
E.printstacktrace ();
}
}
}
Read operation of Io stream