Пример #1
0
Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    //! initialisation of the parameter concern about the network environment
    networkEnvironment = new ccissNetworkEnvironment();
    networkEnvironment->init("self", 12345);
    networkEnvironment->init("piss", 10703, "127.0.0.1");
    //! create tcp server to wait for the connexion from igss_platform part
    server = new ccissServer(networkEnvironment);
    //! create tcp client to connect igss_platform
    ccissToPiss = new ccissClient(networkEnvironment);

//    QDateTime current_date_time = QDateTime::currentDateTime();
//    QString CurrentTime = current_date_time.toString("yyyy-MM-dd hh:mm:ss ddd");
//    qDebug()<<"Data out CurrentTime"<<CurrentTime<<"size"<<CurrentTime.size()<<"sizeof(quint16) size"<<sizeof(quint16);

    tcpServer = new QTcpServer();
    client = new QTcpSocket();

    this->constructIHM();
    this->setConnections();

    loadSize = 4*1024;
    totalBytes = 0;
    bytesWritten = 0;
    bytesToWrite = 0;
    fileSendReady = false;
    msgSendReady = false;
    tcpClient = new QTcpSocket(this);

    connect(tcpClient,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(displayError(QAbstractSocket::SocketError)));
    this->sendButton->setEnabled(false);
//    this->hostLineEdit->setText("127.0.0.1");
//    this->portLineEdit->setText("8888");

    connect(tcpClient,SIGNAL(connected()),this,SLOT(startTransferFile()));
    //当连接服务器成功时,发出connected()信号,我们开始传送文件
    connect(tcpClient,SIGNAL(connected()),this,SLOT(startTransferMsg()));
    //当连接服务器成功时,发出connected()信号,我们开始传送消息
    connect(tcpClient,SIGNAL(bytesWritten(qint64)),this,SLOT(updateClientProgress(qint64)));
    //当有数据发送成功时,我们更新进度条
}
Пример #2
0
/** A file is requested by the host
  *
  * This function is called when the client retirieve a file. The file
  * is sent to the client from the \c uploaded directory.
  *
  * \param filename The filename without path
  *
  */
void RainbruRPG::Network::Ftp::FtpTransfer::
commandRETR(const QString& filename){
  LOGI("Sending file...");
  QString s("Sending file ");
  s+=filename;
  emit(log(s));
  LOGI(s.toLatin1());
  nextCommand=FTC_RETR;

  // Get the absolute filename
  GlobalURI gu;
  std::string stdFilename(filename.toLatin1());
  std::string fullFileName=gu.getUploadFile(stdFilename);
  nextFilename=filename;
  nextOnlyFilename=filename;

  LOGCATS("Opening file '");
  LOGCATS(fullFileName.c_str());
  LOGCAT();

  QFile f(fullFileName.c_str());
  QIODevice::OpenMode om;

  // We are in Binary mode
  if (transferType==FTT_BINARY){
    om=QIODevice::ReadOnly;
  }
  // We are in ASCII mode
  else if (transferType==FTT_ASCII){
    om=QIODevice::ReadOnly|QIODevice::Text;
  }

  if(f.open(om)){
    QTcpSocket sock;
    if (waitForConnection(&sock)){
      emit(startTransferFile(filename, f.size()));
      int rep=0;
      
      while (!f.atEnd()){
	rep=sock.write(f.read(MAX_READ_LENGTH));
	if (rep==-1){
	  LOGE("An error occured during RETR command");
	  break;
	}
	else{
	  LOGCATS("Writing ");
	  LOGCATI(rep);
	  LOGCATS(" bytes");
	  LOGCAT();
	  
	  sock.waitForBytesWritten(3000);
	}
      }
      
      // Transfer complete
      emit(log("Transfer channel closed"));
      emit(transferComplete(filename));
      sock.disconnectFromHost();
      LOGI("Transfer complete");
      f.close();

    }
  }
  else{
    emit(log("An error occured during opening file :"));
    QFile::FileError fe=f.error();

    QString feText;
    if (fe==QFile::OpenError){
      feText=("5 The file could not be opened.");
    }
    else{
      feText.setNum(fe);
    }
    emit(log(feText));
  }
}