[TCP data transmission - keyboard input]

Package com.yjf.esupplier.common.test; 

Import the java.io. * ;
 Import the java.net.Socket; 

/ ** 
 * @author Shusheng 
 * @description the TCP data transmission: keyboard input 
 * @email [email protected] 
 * 2019/1/15 22:57 @date 
 * / 
public  class ClientDemo1 { 

    public  static  void main (String [] args) throws IOException {
         // create a transmission side Socket object 
        Socket Socket = new new Socket ( "localhost", 8888 ); 

        the BufferedReader br = new new the BufferedReader ( new newThe InputStreamReader (the System.in)); 
        BufferedWriter, BW = new new BufferedWriter, ( new new the OutputStreamWriter (Socket.getOutputStream ())); 

        String Line = null ;
         the while ! ((Line = br.readLine ()) = null ) {
             // keyboard input to customize the data end flag 
            IF ( "886" .equals (Line)) {
                 BREAK ; 
            } 
            bw.write (Line); 
            bw.newLine (); 
            bw.flush (); 
        } 

        the Socket.close (); 
    } 

}
Package com.yjf.esupplier.common.test; 

Import the java.io. * ;
 Import the java.net.ServerSocket;
 Import the java.net.Socket; 

/ ** 
 * @author Shusheng 
 * @description the TCP data transmission: keyboard input 
 * @ [email protected] in Email 
 * @date 2019/1/16 21:11 
 * / 
public  class ServerDemo1 { 

    public  static  void main (String [] args) throws IOException {
         // Create the Socket object receiving end 
        the ServerSocket SS = new new the ServerSocket (8888 ); 

        the Socket S = ss.accept();

        BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
        String line = null;
        while((line=br.readLine())!=null){
            System.out.println(line);
        }

        s.close();
    }

}

 

Guess you like

Origin www.cnblogs.com/zuixinxian/p/11275398.html
Recommended