Hi everyone. this is my problem i developed a chat program (voice and text) using framework Qt. i can send and receive text perfectly and also i can send voice over network and receiving it. the problem is i can't do both thing at the same time. can you please help me to send text and voice over network using Qt Framework.
for Sending text :
client side:
messageAEnvoyer ="Christina"
out << (quint16) 0;
out << messageAEnvoyer;
out.device()->seek(0);
out << (quint16) (paquet.size() - sizeof(quint16));
socket->write(paquet);
QString messageAEnvoyer ;
messageAEnvoyer ="Christina"
out << (quint16) 0;
out << messageAEnvoyer;
out.device()->seek(0);
out << (quint16) (paquet.size() - sizeof(quint16));
socket->write(paquet);
To copy to clipboard, switch view to plain text mode
for receiving text :
MessageText *messageArive;
forever{
if (tailleMessage == 0)
{
if (socket->bytesAvailable() < sizeof(tailleMessage))
{
break;
}
in >> tailleMessage;
}
if (socket->bytesAvailable() < tailleMessage){
break;
}
in >> messageRecu;
//do something wih the msg
MessageText *messageArive;
QDataStream in(socket);
forever{
if (tailleMessage == 0)
{
if (socket->bytesAvailable() < sizeof(tailleMessage))
{
break;
}
in >> tailleMessage;
}
if (socket->bytesAvailable() < tailleMessage){
break;
}
QString messageRecu;
in >> messageRecu;
//do something wih the msg
To copy to clipboard, switch view to plain text mode
for voice client side i use
void Widget::on_pushButton_clicked()
{
socket
->connectToHost
(ui
->lineEdit
->text
(),quint16
(5002));
connect(socket,
SIGNAL(error
(QAbstractSocket::SocketError)),
this,
SLOT(error
()));
QAudioFormat format;
format.setSampleRate(44100);
format.setChannelCount(2);
format.setSampleSize(16);
format.setCodec("audio/pcm");
format.setByteOrder(QAudioFormat::LittleEndian);
format.setSampleType(QAudioFormat::SignedInt);
//If format isn't supported find the nearest supported
QAudioDeviceInfo info(QAudioDeviceInfo::defaultInputDevice());
if (!info.isFormatSupported(format))
format = info.nearestFormat(format);
ui->label_2->setText(info.deviceName()); // the supported Input device
QAudioFormat format2;
format2.setSampleRate(44100);
format2.setChannelCount(2);
format2.setSampleSize(16);
format2.setCodec("audio/pcm");
format2.setByteOrder(QAudioFormat::LittleEndian);
format2.setSampleType(QAudioFormat::SignedInt);
QAudioDeviceInfo info2(QAudioDeviceInfo::defaultOutputDevice());
if (!info2.isFormatSupported(format2))
format2 = info2.nearestFormat(format2);
ui->label->setText(info2.deviceName()); // the supported output device
input = new QAudioInput(format);
input->setBufferSize(16384); // set buffere size to solve sound distribution on windows but not solve this problem when use it in android
output = new QAudioOutput(format2);
output->setBufferSize(16384);
device = output->start();
input->start(socket);
connect(socket,SIGNAL(readyRead()),this,SLOT(readyRead()));
}
void Widget::error()
{
ui->label->setText(socket->errorString());
}
}
void Widget::on_pushButton_clicked()
{
socket = new QTcpSocket(this);
socket->connectToHost(ui->lineEdit->text(),quint16(5002)); connect(socket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(error()));
QAudioFormat format;
format.setSampleRate(44100);
format.setChannelCount(2);
format.setSampleSize(16);
format.setCodec("audio/pcm");
format.setByteOrder(QAudioFormat::LittleEndian);
format.setSampleType(QAudioFormat::SignedInt);
//If format isn't supported find the nearest supported
QAudioDeviceInfo info(QAudioDeviceInfo::defaultInputDevice());
if (!info.isFormatSupported(format))
format = info.nearestFormat(format);
ui->label_2->setText(info.deviceName()); // the supported Input device
QAudioFormat format2;
format2.setSampleRate(44100);
format2.setChannelCount(2);
format2.setSampleSize(16);
format2.setCodec("audio/pcm");
format2.setByteOrder(QAudioFormat::LittleEndian);
format2.setSampleType(QAudioFormat::SignedInt);
QAudioDeviceInfo info2(QAudioDeviceInfo::defaultOutputDevice());
if (!info2.isFormatSupported(format2))
format2 = info2.nearestFormat(format2);
ui->label->setText(info2.deviceName()); // the supported output device
input = new QAudioInput(format);
input->setBufferSize(16384); // set buffere size to solve sound distribution on windows but not solve this problem when use it in android
output = new QAudioOutput(format2);
output->setBufferSize(16384);
device = output->start();
input->start(socket);
connect(socket,SIGNAL(readyRead()),this,SLOT(readyRead()));
}
void Widget::error()
{
ui->label->setText(socket->errorString());
}
}
To copy to clipboard, switch view to plain text mode
for receiving voice :
while (socket->bytesAvailable() > 0){
device->write(arr.data(),arr.size());}
while (socket->bytesAvailable() > 0){
QByteArray arr = socket->readAll();
device->write(arr.data(),arr.size());}
To copy to clipboard, switch view to plain text mode
please help me to do both at the sametime thank you so much in advance
Bookmarks