如何在 QT 中通过C++套接字发送和接收
How to send and receive over sockets in C++ in QT?
我想这样做
对于服务器:
QTcpServer qtp;
qtp.listen(QHostAddress::Any, 1440);
qtp.readFromClient(); //What is the name of the method to read the byte from a client ???
qtp.close();
对于客户
QTcpClient client;
client.connect("127.0.0.1", 1440);
client.sendData(myString); // What is the name of the method to do this ???
client.close();
我在 QTcpServer 中找不到用于检索数据和在 QTcpClient 中用于发送数据的方法名称。执行此操作的方法名称是什么?
您可以在阅读文档时看到所有可用的方法。在此链接中,有QTcpSocket继承的QAbstractSocket类的文档。
无论如何,您要使用的方法是write()
发送数据,您可以检查数据是否可用于bytesAvailable()
读取数据以及使用read()
或readData()
读取数据。这些 las 方法是从 QIODevice 类继承和重新实现的,您也可以在文档中找到这些方法。
相关文章:
- 当套接字连接断开时检测C/C++Unix
- 通过套接字[TCP]传输数据 如何在C / C ++中打包多个整数并使用send() recv()传输数据
- 如何通过套接字将文本文件的内容从服务器发送到客户端
- 如何在C/C++中用FD_set Unix设置套接字文件描述符
- 套接字读取后,我在缓冲区中看到意外输入
- 如何在CPP中创建应该在Windows和Linux上运行的套接字?
- 我可以与 python 服务器而不是 c++ 客户端建立 tcp/ip 套接字吗?
- 套接字连接"Operation not permitted"错误,甚至使用升压/平发器根.cpp
- WINAPI 注册应用程序重新启动时不清除打开的套接字
- (Winsock) UDP 接收工作正常,但同一套接字的发送失败
- MSG_WAITALL的套接字发送得到了 22 EINVAL
- C++套接字客户端到 Python 服务器未创建连接
- 在不知道套接字的情况下关闭网络连接
- C++套接字对不读/写父/子
- 非更新套接字消息
- SIGSEGV on Boost UDP 套接字关闭 - tcache_get at malloc.c.
- 将"uint8_t"(从套接字读取)隐式转换为"char"安全吗
- 当对套接字 send() 的同步调用由于连接另一端丢失而被阻止时,如何恢复?
- 当客户端在 write() 期间终止连接时,由对等套接字错误重置连接
- 了解是否接受套接字