Until now, tcpSocket was a session socket for tcpServer, and tcpClient exists aside from that.
If tcpClient continues to exist, the size of libnetwork may get larger than merged one.
)
#Mocs
-set(serverclient_h
- server/tcpserver.h
- client/tcpclient.h
+set(network_h
+ network/tcpnetwork.h
)
set(ui_h
ui/about.h
)
#The implementation files
-set(serverclient_src
- server/tcpserver.cxx
- client/tcpclient.cxx
+set(network_src
+ network/tcpnetwork.cxx
)
set(ui_src
ui/about.cxx
res/main.res
)
-qt4_wrap_cpp(serverclient_moc ${serverclient_h})
+qt4_wrap_cpp(network_moc ${network_h})
qt4_wrap_cpp(ui_moc ${ui_h})
qt4_wrap_ui(ui_moc ${ui})
if(WIN32)
if(OPENMP_FOUND)
add_executable(jasmine WIN32
- ${main} ${ui_moc} ${ui_src} ${serverclient_moc}
- ${serverclient_src} ${structures} ${res_moc}
+ ${main} ${ui_moc} ${ui_src} ${network_moc}
+ ${network_src} ${structures} ${res_moc}
${validator} ${ported_rmd6})
set_property(TARGET jasmine PROPERTY COMPLILE_FLAGS ${OpenMP_CXX_FLAGS} APPEND)
target_link_libraries(jasmine gomp ${QT_LIBRARIES})
else(OPENMP_FOUND)
add_executable(jasmine WIN32
- ${main} ${ui_moc} ${ui_src} ${serverclient_moc}
- ${serverclient_src} ${structures} ${res_moc}
+ ${main} ${ui_moc} ${ui_src} ${network_moc}
+ ${network_src} ${structures} ${res_moc}
${validator} ${ported_rmd6})
target_link_libraries(jasmine ${QT_LIBRARIES})
endif(OPENMP_FOUND)
add_library(resource SHARED ${res_moc})
add_library(structures SHARED ${structures})
- add_library(serverclient SHARED ${serverclient_moc} ${serverclient_src})
+ add_library(network SHARED ${network_moc} ${network_src})
add_library(ui SHARED ${ui_moc} ${ui_src})
add_executable(jasmine ${main})
target_link_libraries(structures ${QT_LIBRARIES})
target_link_libraries(structures qripemd160 ${QT_LIBRARIES})
- target_link_libraries(serverclient structures validator ${QT_LIBRARIES})
- target_link_libraries(ui resource serverclient ${QT_LIBRARIES})
+ target_link_libraries(network structures validator ${QT_LIBRARIES})
+ target_link_libraries(ui resource network ${QT_LIBRARIES})
target_link_libraries(jasmine ui ${QT_LIBRARIES})
if(OPENMP_FOUND)
set_property(TARGET ui PROPERTY COMPILE_FLAGS ${OpenMP_CXX_FLAGS} APPEND)
+ #set_property(TARGET network PROPERTY COMPLE_FLAGS ${OpenMP_CXX_FLAGS} APPEND)
target_link_libraries(ui gomp)
endif(OPENMP_FOUND)
endif(WIN32)
+++ /dev/null
-#include "tcpclient.h"
-#include "../structures/header.h"
-using namespace network;
-using namespace structures;
-tcpClient::tcpClient(quint64 buffersize,const QString &senderName,QObject *parent):QTcpSocket(parent){
- this->buffer_size=buffersize;
- this->senderName=senderName;
- this->timeout_time=TIMEOUT;
- this->want_disconnect=false;
- connect(this,SIGNAL(readyRead()),SLOT(data_available()));
-}
-quint64 tcpClient::timeout()const {return this->timeout_time;}
-void tcpClient::timeout(const quint64 time){this->timeout_time=time;}
-tcpClient &tcpClient::operator<<(const QString &msg){
- if(this->state()!=QAbstractSocket::ConnectedState) return (*this);
- header head_data(this->senderName,msg);
- QByteArray head_buffer;
- QDataStream datastream(&head_buffer,QIODevice::WriteOnly);
- datastream<<head_data;
- quint16 size=(quint16)head_buffer.size();
- this->write((char*)&size,sizeof(__typeof__(size))/sizeof(char));
- if(!this->check_byte_written_and_wait_written())return (*this);
- this->write(head_buffer);
- if(!this->check_byte_written_and_wait_written())return (*this);
- QByteArray array=msg.toUtf8();
- QBuffer memoryStream(&array,this);
- /*while(this->write(memoryStream.read(this->buffer_size))>0)
- if(!this->check_byte_written_and_wait_written())return (*this);*/
- this->write(array);
- if(!this->check_byte_written_and_wait_written())return (*this);
- emit this->sentData();
- return (*this);
-}
-tcpClient &tcpClient::operator<<(QFile &file){
- if(!this->state()!=QAbstractSocket::ConnectedState)return (*this);
- header head_data(this->senderName,QFileInfo(file));
- QByteArray head_buffer;
- QDataStream datastream(head_buffer);
- quint16 size=(quint16)head_buffer.size();
- datastream<<head_data;
- this->write((char*)&size,sizeof(__typeof__(size))/sizeof(char));
- if(!this->check_byte_written_and_wait_written())return (*this);
- this->write(head_buffer);
- if(!this->check_byte_written_and_wait_written())return (*this);
- while(this->write(file.read(this->buffer_size))>0)
- if(!this->check_byte_written_and_wait_written())return (*this);
- emit this->sentData();
- return (*this);
-}
-bool tcpClient::check_byte_written_and_wait_written(){
- this->flush();
- /*if(this->want_disconnect) return false;
- if(!this->waitForBytesWritten(this->timeout_time)){
- this->setErrorString(tr("The data couldn't be written."));
- emit this->error(QAbstractSocket::UnknownSocketError);
- return false;
- }*/
- return true;
-}
-bool tcpClient::check_and_wait_byte_available(){
- if(this->want_disconnect) return false;
- if(!this->waitForReadyRead(this->timeout_time)){
- this->setErrorString(tr("The data couldn't be read."));
- emit this->error(QAbstractSocket::UnknownSocketError);
- return false;
- }
- return true;
-}
-void tcpClient::disconnectFromHostImplementation(){
- this->want_disconnect=true;
- QTcpSocket::disconnectFromHost();
-}
-
-void tcpClient::data_available(){
- this->check_and_wait_byte_available();
- QByteArray receive_data=this->read(1);
- switch(receive_data[0]){
- case 0x00:
- this->disconnectFromHost();
- break;
- default:
- return;
- }
-}
+++ /dev/null
-#pragma once
-#include <QtNetwork>
-//By default, timeout (i.e. connection timeout,sending timeout, and receiving timeout) is 10000 ms. which is 10 sec.
-#define TIMEOUT 10000
-namespace network{
- class tcpClient:public QTcpSocket{
- Q_OBJECT
- public:
- tcpClient(quint64 buffersize,const QString &senderName,QObject *parent=NULL);
- tcpClient &operator<<(const QString &),
- &operator<<(QFile &);
- quint64 timeout() const;
- void timeout(const quint64);
- protected:
- void disconnectFromHostImplementation();
- signals:
- void sentData();
- private slots:
- void data_available();
- private:
- quint64 buffer_size,timeout_time;
- bool check_byte_written_and_wait_written(),
- check_and_wait_byte_available();
- bool want_disconnect;
- QString senderName;
- };
-}
ui \
ui/uifiles \
res \
- client \
- server \
+ network \
ported_rmd6 \
INCLUDEPATH \
+= \
ui/rtfeditor.h \
validator/ipaddressvalidator.h \
structures/header.h \
- server/tcpserver.h \
- client/tcpclient.h \
+ network/tcpnetwork.h \
app_version.h \
settings.h \
definition.h
ui/rtfeditor.cxx \
validator/ipaddressvalidator.cxx \
structures/header.cxx \
- server/tcpserver.cxx \
- client/tcpclient.cxx \
+ network/tcpnetwork.cxx \
settings.cxx \
main.cxx
--- /dev/null
+#include "tcpnetwork.h"
+#include <cstring>
+#include "../structures/header.h"
+
+using namespace network;
+using namespace enc_hash;
+using namespace structures;
+using namespace std;
+tcpServer::tcpServer(quint64 buffersize, QObject *parent):QTcpServer(parent){this->buffersize=buffersize;}
+void tcpServer::incomingConnection(int handle){
+ tcpSocket *socket=new tcpSocket(this->buffersize,this);
+
+ if(!socket->setSocketDescriptor(handle)){
+ emit this->socket_error(*socket);
+ delete socket;
+ return;
+ }
+ emit (emit this->pending(*socket))?this->newConnection():socket->disconnectFromHost();
+}
+
+tcpSocket::tcpSocket(quint64 buffersize, QObject *parent):QTcpSocket(parent){
+ this->buffer_size=buffersize;
+ this->canceled=false;
+ this->event=tcpSocket::headsize;
+ connect(this,SIGNAL(disconnected()),SLOT(deleteLater()));
+ connect(this,SIGNAL(readyRead()),SLOT(read_data()));
+}
+tcpSocket::tcpSocket(const QString &senderName,quint64 buffersize,QObject *parent):QTcpSocket(parent){
+ this->buffer_size=buffersize;
+ this->senderName=senderName;
+}
+void tcpSocket::read_data(){
+ while(this->bytesAvailable()>0){
+ qDebug()<<"Server Event Mode:"<<this->event<<"Server Available bytes:"<<this->bytesAvailable();
+ switch(this->event){
+ case tcpSocket::headsize: this->size_event(); break;
+ case tcpSocket::header_receive: this->header_event(); break;
+ case tcpSocket::data: this->data_event(); break;
+ }
+ }
+}
+void tcpSocket::size_event(){
+ if(this->bytesAvailable()<2) return;
+ char size_buf[2];
+ this->read(size_buf,sizeof(size_buf));
+ memcpy(&this->header_size,size_buf,
+ (sizeof(quint16)>sizeof(__typeof__(size_buf)))?sizeof(quint16):sizeof(size_buf)
+ );
+ this->event=tcpSocket::header_receive;
+}
+void tcpSocket::header_event(){
+ if(this->bytesAvailable()<this->header_size) return;
+ else{
+ QByteArray data=this->read(this->header_size);
+ QDataStream datastream(data);
+ datastream>>this->head_data;
+ if(this->head_data==structures::header()){
+ this->setErrorString(tr("The header is empty."));
+ emit this->error(QAbstractSocket::UnknownSocketError);
+ this->disconnectFromHost();
+ return;
+ }
+ if(!this->head_data.fileName().isEmpty()){
+ this->where_to_save=(emit this->file_pending());
+ if(this->where_to_save.isEmpty()){
+ this->write(QByteArray(1,0x00));
+
+ this->setErrorString(tr("The filename is empty."));
+ emit this->error(QAbstractSocket::UnknownSocketError);
+
+ this->disconnectFromHost();
+ return;
+ }
+ }
+ }
+ this->event=tcpSocket::data;
+}
+void tcpSocket::data_event(){
+ if(this->bytesAvailable()<this->header_data().datasize()) return;
+
+ quint64 final_readsize=this->head_data.datasize()%this->buffer_size,
+ read_count=(this->head_data.datasize()-final_readsize)/this->buffer_size;
+
+ if(this->head_data.fileName().isEmpty()){
+ QByteArray msg;
+ for(quint64 count=0;count<read_count;count++){
+ if(this->check_canceled_then_abort())return;
+ msg+=this->read(this->buffer_size);
+ }
+ if(this->check_canceled_then_abort())return;
+ msg+=this->read(final_readsize);
+
+ rmd6 generator;
+ if(this->head_data.ripemd160()==generator.compute_hash(msg))
+ emit this->msg_received(QString::fromUtf8(msg.data()));
+ else{
+ this->setErrorString(tr("The data has been broken."));
+ emit this->error(QAbstractSocket::UnknownSocketError);
+ this->disconnectFromHost();
+ }
+ }else{
+ streamopen:
+ if(this->where_to_save.isEmpty()){
+ this->setErrorString(tr("The filename is empty."));
+ emit this->error(QAbstractSocket::UnknownSocketError);
+ this->disconnectFromHost();
+ return;
+ }
+ QFile file(this->where_to_save,this);
+ if(!file.open(QIODevice::Truncate|QIODevice::WriteOnly)){
+ this->where_to_save=emit this->fileStream_openFailed(file.error(),file.errorString());
+ goto streamopen;
+ }
+ for(quint64 count=0;count<read_count;count++){
+ if(this->check_canceled_then_abort())return;
+ file.write(this->read(this->buffer_size));
+ emit this->file_receive_progress(file.pos());
+ }
+ if(this->check_canceled_then_abort())return;
+ file.write(this->read(final_readsize));
+ emit this->file_receive_progress(file.pos());
+ file.close();
+
+ rmd6 generator;
+ if(this->head_data.ripemd160()==generator.compute_hash(file))
+ emit this->file_saved();
+ else{
+ this->setErrorString(tr("The file has been broken."));
+ emit this->error(QAbstractSocket::UnknownSocketError);
+ this->disconnectFromHost();
+ }
+ }
+ this->disconnectFromHost();
+}
+
+bool tcpSocket::check_canceled_then_abort(){
+ if(this->canceled){
+ this->setErrorString(tr("The process has been canceled by user."));
+ emit this->error(QAbstractSocket::UnknownSocketError);
+ this->abort();
+ return true;
+ }
+ return false;
+}
+void tcpSocket::disconnectFromHostImplementation(){
+ this->canceled=true;
+ QTcpSocket::disconnectFromHost();
+}
+tcpSocket &tcpSocket::operator<<(const QString &msg){
+ if(this->state()!=QAbstractSocket::ConnectedState) return (*this);
+ this->head_data=header(this->senderName,msg);
+ QByteArray tmp_buffer;
+ QDataStream datastream(&tmp_buffer,QIODevice::WriteOnly);
+ datastream<<this->head_data;
+ quint16 size=(quint16)tmp_buffer.size();
+ this->write((char*)&size,sizeof(__typeof__(size))/sizeof(char));
+ if(!this->flush())return (*this);
+ this->write(tmp_buffer);
+ if(!this->flush())return (*this);
+ tmp_buffer.clear();
+ tmp_buffer=msg.toUtf8();
+ QBuffer memoryStream(&tmp_buffer,this);
+ if(!memoryStream.open(QIODevice::ReadOnly)){
+ this->setErrorString("Memory Stream couldn't open.");
+ emit this->error(QAbstractSocket::UnknownSocketError);
+ return (*this);
+ }
+ while(this->write(memoryStream.read(this->buffer_size))>0)
+ if(!this->flush())return (*this);
+ memoryStream.close();
+
+ emit this->sentData();
+ return (*this);
+}
+tcpSocket &tcpSocket::operator<<(QFile &file){
+ if(!this->state()!=QAbstractSocket::ConnectedState)return (*this);
+ this->head_data=header(this->senderName,QFileInfo(file));
+ QByteArray tmp_buffer;
+ QDataStream datastream(tmp_buffer);
+ quint16 size=(quint16)tmp_buffer.size();
+ datastream<<this->head_data;
+ this->write((char*)&size,sizeof(__typeof__(size))/sizeof(char));
+ if(!this->flush())return (*this);
+ this->write(tmp_buffer);
+ if(!this->flush())return (*this);
+ tmp_buffer.clear();
+ while(this->write(file.read(this->buffer_size))>0)
+ if(!this->flush())return (*this);
+ emit this->sentData();
+ return (*this);
+}
+void tcpSocket::cancel(){this->canceled=true;}
+QString tcpSocket::path_to_save() const{return this->where_to_save;}
+header tcpSocket::header_data() const{return this->head_data;}
--- /dev/null
+#pragma once
+#include <QtNetwork>
+#include "../definition.h"
+#include "../structures/header.h"
+#include "../definition.h"
+#include "../ported_rmd6/rmd6.h"
+
+#define default_bandwidth 0x400
+namespace network{
+ class tcpSocket;
+
+ class tcpServer:virtual public QTcpServer{
+ Q_OBJECT
+ public:
+ tcpServer(quint64 buffersize=default_bandwidth,QObject *parent=NULL);
+ signals:
+ bool pending(const tcpSocket &) const;
+ void socket_error(const tcpSocket &) const;
+ protected:
+ void incomingConnection(int handle);
+ private:
+ quint64 buffersize;
+ };
+
+ class tcpSocket:public QTcpSocket{
+ Q_OBJECT
+ public:
+ //This constructor is for server. it works as a session.
+ tcpSocket(quint64 buffersize=default_bandwidth,QObject *parent=NULL);
+ //This constructor is for client. it works as a client.
+ tcpSocket(const QString &senderName,quint64 buffersize=default_buffer_size,QObject *parent=NULL);
+ QString path_to_save() const;
+ structures::header header_data() const;
+
+ tcpSocket &operator<<(const QString &),
+ &operator<<(QFile &);
+ signals:
+ QString file_pending() const;
+ QString fileStream_openFailed(const QFile::FileError &,const QString &) const;
+
+ void msg_received(const QString &) const;
+
+ void file_receive_progress(const quint64 streamPos) const;
+ void file_saved() const;
+ void sentData();
+ private slots:
+ void read_data();
+ void cancel();
+ protected:
+ void disconnectFromHostImplementation();
+ private:
+ enum mode{headsize,header_receive,data} event;
+ void size_event();
+ void header_event();
+ void data_event();
+ bool check_canceled_then_abort();
+ //The size of header needs to be larger than 0, and smaller than or equal to 0xFFFF.
+ quint16 header_size,buffer_size,timeout_time;
+ structures::header head_data;
+ bool canceled;
+ QString where_to_save;
+ QString senderName;
+ };
+}
+++ /dev/null
-#include "tcpserver.h"
-#include <cstring>
-#include "../structures/header.h"
-
-using namespace network;
-using namespace enc_hash;
-using namespace structures;
-using namespace std;
-tcpServer::tcpServer(quint64 buffersize, QObject *parent):QTcpServer(parent){this->buffersize=buffersize;}
-void tcpServer::incomingConnection(int handle){
- serverSocket *socket=new serverSocket(this->buffersize,this);
-
- if(!socket->setSocketDescriptor(handle)){
- emit this->socket_error(*socket);
- delete socket;
- return;
- }
- emit (emit this->pending(*socket))?this->newConnection():socket->disconnectFromHost();
-}
-
-serverSocket::serverSocket(quint64 buffersize, QObject *parent):QTcpSocket(parent){
- this->buffer_size=buffersize;
- this->canceled=false;
- this->event=serverSocket::headsize;
- connect(this,SIGNAL(disconnected()),SLOT(deleteLater()));
- connect(this,SIGNAL(readyRead()),SLOT(read_data()));
-}
-void serverSocket::read_data(){
- while(this->bytesAvailable()>0){
- qDebug()<<"Server Event Mode:"<<this->event<<"Server Available bytes:"<<this->bytesAvailable();
- switch(this->event){
- case serverSocket::headsize:this->size_event(); break;
- case serverSocket::header: this->header_event(); break;
- case serverSocket::data: this->data_event(); break;
- }
- }
-}
-void serverSocket::size_event(){
- if(this->bytesAvailable()<2) return;
- char size_buf[2];
- this->read(size_buf,sizeof(size_buf));
- memcpy(&this->header_size,size_buf,
- (sizeof(quint16)>sizeof(char))?sizeof(quint16):sizeof(size_buf)
- );
- this->event=serverSocket::header;
-}
-void serverSocket::header_event(){
- if(this->bytesAvailable()<this->header_size) return;
- else{
- QByteArray data=this->read(this->header_size);
- QDataStream datastream(data);
- datastream>>this->head_data;
- if(this->head_data==structures::header()){
- this->abort_receive(serverSocket::header_invalid);
- return;
- }
- if(!this->head_data.fileName().isEmpty()){
- this->where_to_save=(emit this->file_pending((*this)));
- if(this->where_to_save.isEmpty()){
- this->write(QByteArray(1,0x00));
- emit this->receive_aborted((*this),serverSocket::empty_filename_specified);
- this->disconnectFromHost();
- return;
- }
- }
- }
- this->event=serverSocket::data;
-}
-void serverSocket::data_event(){
- if(this->bytesAvailable()<this->header_data().datasize()) return;
-
- quint64 final_readsize=this->head_data.datasize()%this->buffer_size,
- read_count=(this->head_data.datasize()-final_readsize)/this->buffer_size;
-
- if(this->head_data.fileName().isEmpty()){
- QByteArray msg;
- for(quint64 count=0;count<read_count;count++){
- if(this->check_canceled_then_abort())return;
- msg+=this->read(this->buffer_size);
- }
- this->check_canceled_then_abort();
- msg+=this->read(final_readsize);
-
- rmd6 generator;
- if(this->head_data.ripemd160()==generator.compute_hash(msg))
- emit this->msg_received((*this),QString::fromUtf8(msg.data()));
- else emit this->data_broken((*this));
- }else{
- streamopen:
- if(this->where_to_save.isEmpty()){
- this->abort_receive(serverSocket::empty_filename_specified);
- return;
- }
- QFile file(this->where_to_save,this);
- if(!file.open(QIODevice::Truncate|QIODevice::WriteOnly)){
- this->where_to_save=emit this->fileStream_openFailed((*this),file.error(),file.errorString());
- goto streamopen;
- }
- for(quint64 count=0;count<read_count;count++){
- if(this->check_canceled_then_abort())return;
- file.write(this->read(this->buffer_size));
- emit this->file_receive_progress(file.pos(),(*this));
- }
- this->check_canceled_then_abort();
- file.write(this->read(final_readsize));
- emit this->file_receive_progress(file.pos(),(*this));
- file.close();
-
- rmd6 generator;
- if(this->head_data.ripemd160()==generator.compute_hash(file))
- emit this->file_saved((*this));
- else emit this->file_broken((*this));
- }
- this->disconnectFromHost();
-}
-bool serverSocket::check_canceled_then_abort(){
- if(this->canceled){
- this->abort_receive(serverSocket::user);
- return true;
- }
- return false;
-}
-void serverSocket::abort_receive(aborted_reason reason){
- this->write(QByteArray(1,0x00));
- emit this->receive_aborted((*this),reason);
- this->disconnectFromHost();
-}
-void serverSocket::cancel(){this->canceled=true;}
-QString serverSocket::path_to_save() const{return this->where_to_save;}
-header serverSocket::header_data() const{return this->head_data;}
+++ /dev/null
-#pragma once
-#include <QtNetwork>
-#include "../definition.h"
-#include "../structures/header.h"
-#include "../definition.h"
-#include "../ported_rmd6/rmd6.h"
-
-#define default_bandwidth 0x400
-namespace network{
- class serverSocket;
-
- class tcpServer:virtual public QTcpServer{
- Q_OBJECT
- public:
- tcpServer(quint64 buffersize=default_bandwidth,QObject *parent=NULL);
- signals:
- bool pending(const serverSocket &) const;
- void socket_error(const serverSocket &) const;
- protected:
- void incomingConnection(int handle);
- private:
- quint64 buffersize;
- };
-
- class serverSocket:virtual public QTcpSocket{
- Q_OBJECT
- public:
- serverSocket(quint64 buffersize=default_bandwidth,QObject *parent=NULL);
- enum aborted_reason{header_invalid,stream_open_failed,empty_filename_specified,user};
- QString path_to_save() const;
- structures::header header_data() const;
- signals:
- QString file_pending(const serverSocket &socket) const;
- QString fileStream_openFailed(const serverSocket &,const QFile::FileError &,const QString &) const;
-
- void receive_aborted(const serverSocket &,const serverSocket::aborted_reason &);
- void msg_received(const serverSocket &socket,const QString &) const;
- void data_broken(const serverSocket &socket) const;
-
- void file_receive_progress(const quint64 streamPos,const serverSocket &socket) const;
- void file_saved(const serverSocket &socket) const;
- void file_broken(const serverSocket &socket) const;
- private slots:
- void read_data();
- void cancel();
- private:
- enum mode{headsize,header,data} event;
- void size_event();
- void header_event();
- void data_event();
- void abort_receive(aborted_reason reason);
- bool check_canceled_then_abort();
- //The size of header needs to be larger than 0, and smaller than or equal to 0xFFFF.
- quint16 header_size;
- quint64 buffer_size;
- structures::header head_data;
- bool canceled;
- QString where_to_save;
- };
-}
QItemDelegate(parent){}
QWidget *MemberListEditDelegate::createEditor(QWidget *parent,const QStyleOptionViewItem &option,const QModelIndex &index)const{
QLineEdit *editor=qobject_cast<QLineEdit *>(QItemDelegate::createEditor(parent,option,index));
- editor->setValidator(new IPAddressValidator(true,editor));
+ editor->setValidator(new IPAddressValidator(false,editor));
connect(editor,SIGNAL(editingFinished()),SLOT(edit_finished()));
return editor;
}
connect(this->sendTextEditor,SIGNAL(invalidLink(const QString &)),SLOT(invalidLink(const QString &)));
connect(this->sendTextEditor,SIGNAL(sendTriggered()),this->sendButton,SLOT(click()));
- connect(this->mainServer,SIGNAL(pending(const serverSocket &)),SLOT(tcpserver_pending(const serverSocket &)));
+ connect(this->mainServer,SIGNAL(pending(const tcpSocket &)),SLOT(tcpserver_pending(const tcpSocket &)));
}
mainWindow::~mainWindow(){}
void mainWindow::closeEvent(QCloseEvent *event){
#pragma omp parallel for
#endif
for(int index=0;index<addressList.size();index++){
- tcpClient *client=new tcpClient(default_buffer_size,this->setting.name(),this);
+ tcpSocket *client=new tcpSocket(this->setting.name(),default_buffer_size,this);
connect(client,SIGNAL(connected()),SLOT(tcpclient_connected()));
connect(client,SIGNAL(error(const QAbstractSocket::SocketError &)),SLOT(tcpclient_error(const QAbstractSocket::SocketError &)));
client->connectToHost(addressList[index].first,addressList[index].second);
}
}
void mainWindow::tcpclient_error(const QAbstractSocket::SocketError &error){
- tcpClient *client=qobject_cast<tcpClient *>(this->sender());
+ tcpSocket *client=qobject_cast<tcpSocket *>(this->sender());
qDebug()<<"Error:"<<client->errorString();
+ client->close();
}
void mainWindow::tcpclient_connected(){
- tcpClient *client=qobject_cast<tcpClient *>(this->sender());
+ tcpSocket *client=qobject_cast<tcpSocket *>(this->sender());
(*client)<<this->sendTextEditor->html();
client->disconnectFromHost();
client->close();
settings mainWindow::app_setting() const{return this->setting;}
//Implementations for main server.
-bool mainWindow::tcpserver_pending(const serverSocket &socket){
+bool mainWindow::tcpserver_pending(const tcpSocket &socket){
if(!this->isInMember(AddressAndPort(socket.peerAddress(),0),true)) return false;
connect(&socket,
- SIGNAL(msg_received(const serverSocket &,const QString &)),
- SLOT(tcpserver_msg_received(const serverSocket &,const QString &)));
- connect(&socket,SIGNAL(receive_aborted(const serverSocket &,const serverSocket::aborted_reason &)),
- SLOT(tcpserver_receive_aborted(const serverSocket &,const serverSocket::aborted_reason &)));
+ SIGNAL(msg_received(const QString &)),
+ SLOT(tcpserver_msg_received(const QString &)));
+ connect(&socket,SIGNAL(error(const QAbstractSocket::SocketError &)),
+ SLOT(tcpserver_error(const QAbstractSocket::SocketError &)));
return true;
}
-void mainWindow::tcpserver_receive_aborted(const serverSocket &socket,const serverSocket::aborted_reason &reason){
- Q_UNUSED(socket);
- qDebug()<<"Receive aborted:"<<reason;
+void mainWindow::tcpserver_error(const QAbstractSocket::SocketError &error){
+ tcpSocket *sender=qobject_cast<tcpSocket *>(this->sender());
+ qDebug()<<"Receive aborted:"<<sender->errorString();
}
-void mainWindow::tcpserver_msg_received(const serverSocket &socket,const QString &msg){
- this->receiveText->append(socket.header_data().senderName()+"("+socket.peerAddress().toString()+")"+tr(" says:"));
- this->receiveText->append(msg);
- this->receiveText->append("<br />");
+void mainWindow::tcpserver_msg_received(const QString &msg){
+ tcpSocket *sender=qobject_cast<tcpSocket *>(this->sender());
+ this->receiveText->append(sender->header_data().senderName()+"("+sender->peerAddress().toString()+")"+tr(" says:"));
+ this->receiveText->append(msg+"\n");
+ //this->receiveText->append("<br />");
}
#include "rtfeditor.h"
#include "../settings.h"
#include "../validator/ipaddressvalidator.h"
-#include "../server/tcpserver.h"
-#include "../client/tcpclient.h"
+#include "../network/tcpnetwork.h"
using namespace structures;
using namespace network;
void tcpclient_connected();
void tcpclient_error(const QAbstractSocket::SocketError &error);
//These functions are for tcpserver.
- bool tcpserver_pending(const serverSocket &);
- void tcpserver_msg_received(const serverSocket &,const QString &);
- void tcpserver_receive_aborted(const serverSocket &,const serverSocket::aborted_reason &);
+ bool tcpserver_pending(const tcpSocket &);
+ void tcpserver_msg_received(const QString &);
+ void tcpserver_error(const QAbstractSocket::SocketError &);
public slots:
//These are for opening stuff.
void openConfig(const QString &);
QList<AddressAndPort> ret;
for(int row=0;row<this->rowCount();row++){
QStringList address_port_str=this->item(row,AddressIndex)->text().split(":");
- if(address_port_str.size()<2||address_port_str[1].isEmpty()) address_port_str[1]=QString("%1").arg(default_port);
- AddressAndPort address_port(QHostAddress(address_port_str[0]),address_port_str[1].isEmpty()?default_port:address_port_str[1].toUShort());
+ if(address_port_str.size()<2) address_port_str<<QString("%1").arg(default_port);
+ if(address_port_str[1].isEmpty()) address_port_str[1]=QString("%1").arg(default_port);
+ AddressAndPort address_port(QHostAddress(address_port_str[0]),address_port_str[1].toUShort());
ret<<address_port;
}
return ret;