📄 tcpclient.java
字号:
package com.demo.struts.else_test;
import java.io.*;
import java.net.*;
public class TcpClient {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
Socket soc = null;
InputStream is = null;
OutputStream os = null;
DataInputStream in = null;
PrintStream out = null;
String strin = null;
try{
soc = new Socket("localhost",8000);
System.out.println("Conceting to the server..........");
is = soc.getInputStream();
os = soc.getOutputStream();
in = new DataInputStream(is);
out = new PrintStream(os);
strin = in.readLine();
System.out.println("Server said:" + strin);
byte[] bmsg = new byte[20];
System.in.read(bmsg);
String msg = new String(bmsg, 0);
msg = msg.trim();
while(!msg.equals("quit")){
out.println(msg);
System.in.read(bmsg);
msg = new String(bmsg, 0);
msg = msg.trim();
}
out.println(msg);
}catch(Exception e){
System.out.println("error:" + e);
}
finally{
is.close();
os.close();
soc.close();
System.exit(0);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -