求助啊~QTCPSOCKET连接问题

qq_33535692 2017-09-09 10:04:04

这个时QT端的发送



服务端接收数据:
System.out.println("等待连接");
Socket socket=ss.accept();
InputStream is=socket.getInputStream();
BufferedReader br=new BufferedReader(new InputStreamReader(is));
String info=null;
while(!((info=br.readLine())==null)){
System.out.println("我是服务器,用户信息为:"+info);
}


为什么我要端开连接后服务端才会显示数据。就是我关闭客户端后才能收到数据


...全文
476 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
DreamLife. 2017-09-30
  • 打赏
  • 举报
回复
我就知道,看论坛可以学习到很多东西,哈哈哈哈哈
zhenimei100 2017-09-30
  • 打赏
  • 举报
回复
你的问题应该是connectToHost之后,立即去write了。 connectToHost要过会才能连上啊。
  • 打赏
  • 举报
回复
是的,需要调flush刷新一下缓冲区:client->flush(); 或者你可以调一下waitForBytesWritten() ;等待数据写入。 bool QAbstractSocket::flush() This function writes as much as possible from the internal write buffer to the underlying network socket, without blocking. If any data was written, this function returns true; otherwise false is returned. Call this function if you need QAbstractSocket to start sending buffered data immediately. The number of bytes successfully written depends on the operating system. In most cases, you do not need to call this function, because QAbstractSocket will start sending data automatically once control goes back to the event loop. In the absence of an event loop, call waitForBytesWritten() instead.
橙儿稻香 2017-09-28
  • 打赏
  • 举报
回复
。。。估计是数据量太小 所以在缓存里 试试flush 直接发送
qq_33535692 2017-09-09
  • 打赏
  • 举报
回复
我要断开socket连接后服务器才能收到数据。

16,212

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧