Skip to content

Commit

Permalink
创建会议
Browse files Browse the repository at this point in the history
  • Loading branch information
muleimulei committed Jun 3, 2021
1 parent d6fe114 commit 4867700
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 14 deletions.
33 changes: 24 additions & 9 deletions mytcpsocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "netheader.h"
#include <QHostAddress>
#include <QtEndian>
#include <QMetaObject>

extern QUEUE_SEND queue_send;
extern QUEUE_RECV queue_recv;
Expand All @@ -13,18 +14,28 @@ MyTcpSocket::MyTcpSocket()
_sockThread = new QThread();
this->moveToThread(_sockThread);
sendbuf =(uchar *) malloc(2 * MB);
connect(_socktcp, SIGNAL(readyRead()), this, SLOT(recvFromSocket()));
connect(_socktcp, SIGNAL(readyRead()), this, SLOT(recvFromSocket())); //接受数据
connect(_socktcp, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(errorDetect(QAbstractSocket::SocketError)));
qRegisterMetaType<QAbstractSocket::SocketError>();
}

void MyTcpSocket::errorDetect(QAbstractSocket::SocketError error)
{
emit socketerror(error);
}

void MyTcpSocket::run()
{


quint64 bytestowrite = 0;
//构造消息头
sendbuf[0] = '$';
quint32 ip = _socktcp->localAddress().toIPv4Address();
qToBigEndian<quint32>(ip, sendbuf + 1);


// $_IPV4_MSGType_MSGSize_# // 12
// 1 4 2 4 1
// 底层写数据线程
for(;;)
{
Expand All @@ -44,10 +55,11 @@ void MyTcpSocket::run()
{
qToBigEndian<quint16>(CREATE_MEETING, sendbuf + bytestowrite);
bytestowrite += 2;
}
sendbuf[bytestowrite] = '#';

bytestowrite ++;
qToBigEndian<quint32>(bytestowrite + 5, sendbuf + bytestowrite);
sendbuf[bytestowrite+4] = '#';
bytestowrite += 5;
}

qint64 hastowrite = bytestowrite;
qint64 ret = 0, haswrite = 0;
Expand All @@ -66,7 +78,8 @@ void MyTcpSocket::run()
haswrite += ret;
hastowrite -= ret;
}
qDebug() << "send success";

_socktcp->waitForBytesWritten();

if(send->msg_type == CREATE_MEETING)
{
Expand All @@ -77,7 +90,9 @@ void MyTcpSocket::run()

void MyTcpSocket::recvFromSocket()
{

char buf[100];
_socktcp->read(buf, 100);
qDebug() << QString(buf);
}

MyTcpSocket::~MyTcpSocket()
Expand Down Expand Up @@ -105,11 +120,11 @@ QString MyTcpSocket::errorString()

void MyTcpSocket::disconnectFromHost()
{
if(this->isRunning())
if(this->isRunning()) // read
{
this->quit();
}
if(_sockThread->isRunning())
if(_sockThread->isRunning()) //write
{
_sockThread->quit();
}
Expand Down
5 changes: 5 additions & 0 deletions mytcpsocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ class MyTcpSocket: public QThread
QTcpSocket *_socktcp;
QThread *_sockThread;
uchar *sendbuf;
private slots:
void errorDetect(QAbstractSocket::SocketError);
public slots:
void recvFromSocket();

signals:
void socketerror(QAbstractSocket::SocketError);
};

#endif // MYTCPSOCKET_H
2 changes: 1 addition & 1 deletion sendtext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void SendText::push_Text(MSG_TYPE msgType, QString str)
queue_waitCond.wait(&textqueue_lock);
}
textqueue.push_back(M(str, msgType));
// qDebug() << "jiaru";
qDebug() << "jiaru";
textqueue_lock.unlock();
queue_waitCond.wakeAll();
}
Expand Down
34 changes: 31 additions & 3 deletions widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ Widget::Widget(QWidget *parent)

//数据处理
_mytcpSocket = new MyTcpSocket(); // 专管发送
connect(_mytcpSocket, SIGNAL(socketerror(QAbstractSocket::SocketError)), this, SLOT(mytcperror(QAbstractSocket::SocketError)));

//文本传输
_sendText = new SendText();

//配置摄像头
_camera = new QCamera(this);
Expand Down Expand Up @@ -85,9 +88,16 @@ void Widget::on_createmeetBtn_clicked()
{
if(false == _createmeet)
{
_createmeet = true;
ui->createmeetBtn->setDisabled(true);
ui->exitmeetBtn->setDisabled(false);
ui->openAudio->setDisabled(true);
ui->openVedio->setDisabled(true);
ui->exitmeetBtn->setDisabled(true);
_sendText->push_Text(CREATE_MEETING); //将 “创建会议"加入到发送队列


// _createmeet = true;
// ui->createmeetBtn->setDisabled(true);
// ui->exitmeetBtn->setDisabled(false);
}
}

Expand All @@ -111,6 +121,7 @@ void Widget::on_exitmeetBtn_clicked()
{
_camera->stop();
}

ui->createmeetBtn->setDisabled(true);
ui->exitmeetBtn->setDisabled(false);
_createmeet = false;
Expand Down Expand Up @@ -141,7 +152,8 @@ void Widget::on_openVedio_clicked()
_sendImg->quit();
ui->openVedio->setText("开启摄像头");
}
}else
}
else
{
_camera->start(); //开启摄像头
if(_camera->error() == QCamera::NoError)
Expand Down Expand Up @@ -183,6 +195,10 @@ void Widget::on_connServer_clicked()
ui->createmeetBtn->setDisabled(false);
ui->exitmeetBtn->setDisabled(false);
QMessageBox::warning(this, "Connection success", "成功连接服务器" , QMessageBox::Yes, QMessageBox::Yes);

//开启文本传输线程
_sendText->start();
ui->connServer->setDisabled(true);
}
else
{
Expand All @@ -196,3 +212,15 @@ void Widget::cameraError(QCamera::Error)
{
QMessageBox::warning(this, "Camera error", _camera->errorString() , QMessageBox::Yes, QMessageBox::Yes);
}

void Widget::mytcperror(QAbstractSocket::SocketError err)
{
if(err == QAbstractSocket::RemoteHostClosedError)
{
QMessageBox::warning(this, "Tcp error", _mytcpSocket->errorString() , QMessageBox::Yes, QMessageBox::Yes);
ui->createmeetBtn->setDisabled(true);
ui->exitmeetBtn->setDisabled(true);
ui->connServer->setDisabled(false);
ui->outlog->setText(QString("远程服务器关闭"));
}
}
4 changes: 3 additions & 1 deletion widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QTcpSocket>
#include "mytcpsocket.h"
#include <QCamera>
#include "sendtext.h"
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE
Expand All @@ -32,6 +33,7 @@ class Widget : public QWidget
QThread *_imgThread;


SendText * _sendText;
//socket
MyTcpSocket * _mytcpSocket;
void paintEvent(QPaintEvent *event);
Expand All @@ -44,9 +46,9 @@ private slots:
void on_exitmeetBtn_clicked();

void on_openVedio_clicked();

void on_connServer_clicked();
void cameraError(QCamera::Error);
void mytcperror(QAbstractSocket::SocketError);
private:
Ui::Widget *ui;
};
Expand Down

0 comments on commit 4867700

Please sign in to comment.