双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

我作了个TCP通信,服务端接收信息后不能返回给客户端信息

jade0428 jade0428 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
如题目,帮忙检查一下程序问题出在哪?谢谢了~~~
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) {
}
}

}
public static void main(String[] args) {
client client1 = new client();
}

}
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
jade0428
Java SE 62,621 成员 307,251 内容