- import java.io.BufferedReader;
- import java.io.DataOutputStream;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.io.OutputStream;
- import java.net.InetAddress;
- import java.net.Socket;
- public class TcpClient {
- public static void main(String[] args) throws Exception{
- if(args.length < 2){
- System.out.println("Usage:java TcpClient ServerIP ServerPort");
- return ;
- }
- Socket s = new Socket(InetAddress.getByName(args[0]),Integer.parseInt(args[1]));
- InputStream ips = s.getInputStream();
- OutputStream ops = s.getOutputStream();
- BufferedReader brKey = new BufferedReader(new InputStreamReader(System.in));
- DataOutputStream dos = new DataOutputStream(ops);
- BufferedReader brNet = new BufferedReader(new InputStreamReader(ips));
-
- while(true){
- String strWord = brKey.readLine();
- //帮忙解释一下下面这句
- dos.writeBytes(strWord + System.getProperty("line.separator"));
- if("quit".equalsIgnoreCase(strWord)){
- break;
- } else {
- System.out.println(brNet.readLine());
- }
- }
- dos.close();
- brNet.close();
- brKey.close();
- s.close();
- }
- }
复制代码 此段代码中的System.getProperty("line.separator")是什么意思 |
|