client执行没有显示
我按照视频里的打完后 按顺序执行 server正常显示,client 执行后不报错也不显示
client:
package com.socketTCP;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
public class client {
public static void main (String[] args) {
try {
Socket socket = new Socket ("localhost",1718);
OutputStream os = socket.getOutputStream();
PrintWriter pw = new PrintWriter(os);
pw.write("用户名:admin ; 密码:123");
pw.flush();
socket.shutdownOutput();
pw.close();
os.close();
socket.close();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
server:
package com.socketTCP;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
public class Server {
public static void main(String[] args) {
try {
ServerSocket serversocket = new ServerSocket(1718);
System.out.println("服务器即将启动,等待连接");
Socket socket = serversocket.accept();
InputStream is = socket.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String info = null;
while((info = br.readLine())!= null){
System.out.println("我是服务器,客户端说:"+info);
}
socket.shutdownInput();
br.close();
isr.close();
is.close();
socket.close();
serversocket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}