?? tcpclient_yanggx.java
字號:
package com.jk.net;
import java.net.*;
import java.io.*;
public class TCPClient_yanggx {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String address = "10.22.78.19";
int port = 8888;
Socket s = null;
InputStream is = null;
OutputStream os = null;
PrintWriter pw = null;
BufferedReader br = null;
try {
//1. 獲得socket
s = new Socket(address, port);
//2. 獲得輸入輸出流
os = s.getOutputStream();
//3. 包裝輸出流
//字節流到字符流的轉換
pw = new PrintWriter((new OutputStreamWriter(os, "UTF-8")), true);
//4. 發送
pw.println("please give me your time now!!");
//5. 獲得輸入流
is = s.getInputStream();
//6. 包裝輸入流
br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
//7. 接收
System.out.println(br.readLine());
//8. 關閉
br.close();
is.close();
pw.close();
os.close();
s.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -