C++ socket 服务器,java socket客户端
java客户端可以向服务器发送数据,但是却接收不到服务器send的数据,一直处于readline()的阻塞状态:java客户端代码reader=newBufferedRe...
java 客户端可以向服务器发送数据,但是却接收不到服务器send的数据,一直处于readline()的阻塞状态: java 客户端代码 reader = new BufferedReader(new InputStreamReader(socket.getInputStream())); writer = new PrintWriter(socket.getOutputStream(),true); writer.write("dsadasdasdsadsad"); writer.flush(); String str = null; if((str = reader.readLine())!=null) { System.out.println(str); }
c++ 服务端代码
while ( true )
{
memset(RecvBuffer, 0x00, sizeof(RecvBuffer));
Ret = recv(CientSocket, RecvBuffer, MAX_PATH, 0);
if ( Ret == 0 || Ret == SOCKET_ERROR )
{
cout<<"客户端退出!"<<endl;
closesocket(CientSocket);
break;
}
cout<<"接收到客户信息为:"<<RecvBuffer<<endl;
int datalen = send(CientSocket, RecvBuffer, strlen(RecvBuffer)+1,0);
cout<<datalen<<endl;
} 展开
c++ 服务端代码
while ( true )
{
memset(RecvBuffer, 0x00, sizeof(RecvBuffer));
Ret = recv(CientSocket, RecvBuffer, MAX_PATH, 0);
if ( Ret == 0 || Ret == SOCKET_ERROR )
{
cout<<"客户端退出!"<<endl;
closesocket(CientSocket);
break;
}
cout<<"接收到客户信息为:"<<RecvBuffer<<endl;
int datalen = send(CientSocket, RecvBuffer, strlen(RecvBuffer)+1,0);
cout<<datalen<<endl;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询