java客户端访问c写的服务端 接收不到返回数据
大家好,现在需要实现一个简单的socket通讯
服务端是用纯C编写的,客户端为java,我想实现的功能是测试客户和服务端的连接是否畅通,
现在我的问题是:
我发给服务器的字符串接马上可以收到了,但是服务端返回的字符串我接收的很慢,有时候服务端程序关闭后客户端才能收到,(注:我测试的时候服务端和客户端部署到一台机子 服务端和客户端不在同一台机子 都试验过了)
现贴出我的客户端的java 代码
try
{
socket=new Socket("localhost",9001);
PrintWriter out=new PrintWriter(socket.getOutputStream());
BufferedReader wt=new BufferedReader(new InputStreamReader(System.in));
String str ="hello";
out.print(str);
out.flush();
System.out.println(in.readLine()); //打印返回的字符串
socket.close();
}
catch (IOException e)
{
e.printStackTrace();
}