我作了个TCP通信,服务端接收信息后不能返回给客户端信息
如题目,帮忙检查一下程序问题出在哪?谢谢了~~~
server端:
public class server {
public server() {
try {
ServerSocket socket = new ServerSocket(8877, 20);
System.out.println( "服务端已经启动 ");
while(true)
{
BufferedInputStream br = new BufferedInputStream(socket.accept().getInputStream());
byte[] bytes = new byte[1024];
int notelen = br.read(bytes);
String noteinfo = new String(bytes, 0, notelen); //接收发送过来的信息
System.out.println(noteinfo);
PrintWriter pw = new PrintWriter(socket.accept().getOutputStream());
pw.println( "server ");
pw.flush();
}
}
catch (
IOException ex) {
}
}
public static void main(String[] args) {
server server1 = new server();
}
}
client端:
public class client {
public client() {
InetSocketAddress it = new InetSocketAddress( "192.168.0.32 ", 8877);
Socket socket=new Socket();
try {
socket.connect(it, 1000);
PrintWriter pw=new PrintWriter(socket.getOutputStream());
pw.println( "client ");
pw.flush();
DataInputStream isr = new DataInputStream(socket.getInputStream());
String result = isr.readLine();
System.out.println(result);
isr.close();
}
catch (IOException ex) {
System.out.println(ex);
}
finally{
try {
socket.close();
}
catch (IOException ex1) {
}
}
}