【发布时间】:2014-01-30 21:38:34
【问题描述】:
我正在做一个小型客户端/服务器预订应用程序,我坚持如何发送课程的信息,实际上我有 3 个课程,我正在发送这样的信息:
VentanaPrincipalS::VentanaPrincipalS(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::VentanaPrincipalS)
{
//..Methods..//
connect(conexion,SIGNAL(nuevaConexion(QTcpSocket*)), this, SLOT(enviarDataCliente(QTcpSocket*)));
connect(conexion,SIGNAL(nuevaConexion(QTcpSocket*)), this, SLOT(enviarDataVuelo(QTcpSocket*)));
connect(conexion,SIGNAL(nuevaConexion(QTcpSocket*)), this, SLOT(enviarDataReservacion(QTcpSocket*)));
//..Methods..//
}
void VentanaPrincipalS::enviarDataVuelo(QTcpSocket *sock)
{
QByteArray buffer;
QDataStream out(&buffer, QIODevice::ReadWrite);
out << 1;
for(int i = 0; i < empresa.cantidadVuelos(); i++){
out << empresa.getVuelos().at(i)->getDestino() << empresa.getVuelos().at(i)->getIdVuelo() << empresa.getVuelos().at(i)->getPartida();
}
if(sock->isValid())
{
sock->write(buffer);
}
}
//2 More methods just like this, switching the out first number
to know which class is...//
在客户端我收到这样的:
in>> caracterControl;
switch(caracterControl){
case 1:{
while(!in.atEnd()){
QString destino;
QString id;
QDate fecha;
in >> destino >> id >> fecha;
qDebug()<< destino +" "+ id + " " + fecha.toString();
MVuelo vuelop(id, destino, fecha);
listaVuelos.append(id);
vuelosRecibidos.push_back(vuelop);
}
}
case 2:{
while(!in.atEnd()){
QString cedula;
QString correo;
QString nombre;
QString telf;
in >> cedula >> correo >> nombre >> telf;
MCliente cliente(nombre, cedula, telf, correo);
qDebug()<< "Cliente: " + cedula;
}
}
case 3:{
while(!in.atEnd()){
QString reserva;
QString vuelo;
in >> reserva >> vuelo;
qDebug()<< "Reserva: " + reserva;
}
}
}
1、2 或 3,取决于类别。
问题是信息不完整,就像socket一样 崩溃是因为另一种方法正在写在他身上,有没有办法接收所有 信息的顺序或告诉服务器套接字完成读取的方法?
请帮帮我;(...
PD:是的,服务器和套接字连接成功,我确定 :)
注意:我有一个带有 3 个客户端(21727090、20350202 和 123)的 QList,并且我通过 qDebug() 接收到这个低谷
2
“客户:21727090”
“客户:20350202”
“客户:123”
“客户:”
“客户:”
“客户:”
【问题讨论】:
-
是什么让您认为可以同时在 TCP 套接字中发送各种数据? TCP 是基于流的,一切都是按顺序发生的。
-
嗯,这种 adios-amigos 语言使它比它可能的更难理解。
-
你推荐什么 SirDarius?
-
一年后这个问题还没有解决吗??
标签: c++ multithreading qt sockets qtcpsocket