?? tcpclient.java
字號:
package tcpclientdemo;
import java.net.*;
import java.io.*;
public class TcpClient {
public static void main(String[] args) {
Socket cli=null;
InputStream is = null;
OutputStream os = null;
BufferedReader br = null;
BufferedWriter bw = null;
try {
cli=new Socket("127.0.0.1",9999);
is=cli.getInputStream();
os=cli.getOutputStream();
br=new BufferedReader(
new InputStreamReader(is));
bw=new BufferedWriter(
new OutputStreamWriter(os));
bw.write("i am tester!");
bw.newLine();
bw.flush();
String str=br.readLine();
System.out.println("client:"+str);
} catch (Exception ex) {
System.out.println("ex in client :"+
ex.getMessage());
}
finally
{
try {
bw.close();
} catch (Exception e) {}
try {
br.close();
} catch (Exception e) {}
try {
os.close();
} catch (Exception e) {}
try {
is.close();
} catch (Exception e) {}
try {
cli.close();
} catch (Exception e) {}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -