The client sends text to the server. The service side converts text to uppercase in return to the client

Source: Internet
Author: User
Tags flush readline


/*
* Create a text conversion server
* The client sends text to the server. The service side converts text to uppercase in return to the client
* And the client can continue to text conversion, when the customer input over the
* Conversion End
*/
public class C {
public static void Main (string[] args) throws Unknownhostexception, IOException {
Socket s=new socket ("10.218.24.253", 10008);
BufferedReader bufr=new BufferedReader (New InputStreamReader (system.in));

BufferedWriter bufwout=new BufferedWriter (New OutputStreamWriter (S.getoutputstream ()));

BufferedReader bufrin=new BufferedReader (New InputStreamReader (S.getinputstream ()));

String Line=null;
while ((Line=bufr.readline ())!=null) {

if (' over '. Equals (line)) {
Break
}
Bufwout.write (line);
Bufwout.newline ();
Bufwout.flush ();
String Str=bufrin.readline ();
}
Bufr.close ();
S.close ();
}


}

//****************************************

Public class S {
The public static void main (string[] args) throws IOException {
ServerSocket ss=new serversocket (100 08);
Socket s=ss.accept ();
BufferedReader bufin=new BufferedReader (New InputStreamReader (S.getinputstream ()));
BufferedWriter bufout=new BufferedWriter (New OutputStreamWriter (S.getoutputstream ()));
String Line=null;
while ((Line=bufin.readline ())!=null) {
Bufout.write (line.touppercase ());
Bufout.newline ();
Bufout.flush ();
}
S.close ();
Ss.close ();

}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.