Java Network Programming (6)--Implement a server to capitalize lowercase

Source: Internet
Author: User
Tags closing tag

Implement a server, through the text data we send, and then back to capitalization, to achieve a service-side interaction with the client, with over as the closing tag, the specific code is as follows:

Client:

 Packagecom.seven.tcp;ImportJava.io.BufferedReader;ImportJava.io.BufferedWriter;ImportJava.io.InputStreamReader;ImportJava.io.OutputStreamWriter;ImportJava.net.Socket; Public classtranclient { Public Static voidMain (string[] args)throwsexception{Socket Socket=NewSocket ("127.0.0.1", 10001); //text data, using a character stream, reading the keyboardBufferedReader reader =NewBufferedReader (NewInputStreamReader (system.in)); //responsible for writingBufferedWriter writer =NewBufferedWriter (NewOutputStreamWriter (Socket.getoutputstream ())); //Read return DataBufferedReader in =NewBufferedReader (NewInputStreamReader (Socket.getinputstream ())); String Line=NULL;  while(line = Reader.readline ())! =NULL){            if("Over". Equals (line)) {                 Break;            } writer.write (line);            Writer.newline ();                        Writer.flush (); System.out.println ("Server return:" +in.readline ());        } reader.close ();                        Socket.close (); }}

Service side:

 Packagecom.seven.tcp;ImportJava.io.BufferedReader;ImportJava.io.BufferedWriter;ImportJava.io.InputStreamReader;ImportJava.io.OutputStreamWriter;ImportJava.net.ServerSocket;ImportJava.net.Socket; Public classTranserver { Public Static voidMain (string[] args)throwsException {serversocket serversocket=NewServerSocket (10001); Socket Socket=serversocket.accept (); //reading DataBufferedReader reader =NewBufferedReader (NewInputStreamReader (Socket.getinputstream ())); //Write back DataBufferedWriter writer =NewBufferedWriter (NewOutputStreamWriter (Socket.getoutputstream ())); String Line=NULL;  while(line = Reader.readline ())! =NULL) {writer.write (Line.touppercase ());            Writer.newline ();        Writer.flush ();        } writer.close ();            Socket.close (); }    }

This way, you can implement lowercase capitalization, enter over to end the connection = =.

Java Network Programming (6)--Implement a server to capitalize lowercase

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.