int main(int argc, char *argv[])
{
   int sock, n;
   unsigned int length;
   struct sockaddr_in server, from;
   struct hostent *hp;
   char buffer[256];
   
   if (argc != 3) { printf("Usage: server port\n");
                    exit(1);
   }
   sock= socket(AF_INET, SOCK_DGRAM, 0);
   if (sock < 0) error("socket");

   server.sin_family = AF_INET;
   hp = gethostbyname(argv[1]);
   if (hp==0) error("Unknown host");

   bcopy((char *)hp->h_addr, 
        (char *)&server.sin_addr,
         hp->h_length);
   server.sin_port = htons(atoi(argv[2]));
   length=sizeof(struct sockaddr_in);
   cout<<"connecting sock!\n";
   
   string file = readAllFile("1.txt");

   cout<<"file: "<<file<<endl;
   
   char* filep= (char*)malloc((file.size()+1)*sizeof(char));
   
   memcpy(filep, file.c_str(), file.size()+1);

   cout<<"try to send "<<filep<<endl;

   sendFrame(filep, file.size()+1, address(0), address(0), sock, &server);
      
   /*Packet p;
   p.setData("salam", 6);
   p.send(sock, atoi(argv[2]));
   p.recive(sock, &from);

   p.getData(buffer);
   cout<<buffer<<endl;

   printf("Please enter the message: ");
   bzero(buffer,256);
   fgets(buffer,255,stdin);
   n=send(sock,buffer,
            strlen(buffer),0);
   if (n < 0) error("Sendto");
   n = recvfrom(sock,buffer,256,0,(struct sockaddr *)&from, &length);
   if (n < 0) error("recvfrom");
   write(1,"Got an ack: ",12);
   write(1,buffer,n);*/
   close(sock);
   return 0;
}
Пример #2
0
void choseWaveToExtract::refreshOptChoi()
{
    //----------------------------------------------
    //Clear tables
    //----------------------------------------------
    while (ui->tableOptions->rowCount() > 0)
    {
        ui->tableOptions->removeRow(0);
    }
    while (ui->tableChoises->rowCount() > 0)
    {
        ui->tableChoises->removeRow(0);
    }

    //----------------------------------------------
    //Fill tables
    //----------------------------------------------
    QString options, choises;
    options = readAllFile(_PATH_WAVE_OPTIONS);
    choises = readAllFile(_PATH_WAVE_CHOISES);
    QList<QString> lstOptions   = options.split(",");
    QList<QString> lstChoises   = choises.split(",");
    QList<float> lstOptNumber;
    QList<float> lstChoisesNumber;
    int i;
    for(i=1;i<lstOptions.size();i++)
        lstOptNumber.append(lstOptions.at(i).toFloat());
    for(i=1;i<lstChoises.size();i++)
        lstChoisesNumber.append(lstChoises.at(i).toFloat());

    std::sort(lstOptNumber.begin(), lstOptNumber.end());
    std::sort(lstChoisesNumber.begin(), lstChoisesNumber.end());

    Q_FOREACH(const float option, lstOptNumber)
    {
        insertRow(QString::number(option),ui->tableOptions);
    }
Пример #3
0
NetStatPrivate::NetStatPrivate(NetStat *parent)
    : BaseStatPrivate(parent)
{
    mSource = defaultSource();

    connect(mTimer, SIGNAL(timeout()), SLOT(timeout()));


    QStringList rows(readAllFile("/proc/net/dev").split(QChar('\n'), QString::SkipEmptyParts));

    rows.erase(rows.begin(), rows.begin() + 2);

    foreach (QString row, rows)
    {
        QStringList tokens = row.split(QChar(':'), QString::SkipEmptyParts);
        if (tokens.size() != 2)
            continue;

        mSources.append(tokens[0].trimmed());
    }
Пример #4
0
void CObjInfo::init(CMapView *map, const mapView_t *view, const mapObj_t *obj)
//////////////////////////////////////////////////////////////////////////////
{
  CObjFillInfo info;

  m_map = map;

  ui->pushButton_3->setEnabled(false);
  ui->clb_slew->setEnabled(g_pTelePlugin && (g_pTelePlugin->getAttributes() & TPI_CAN_SLEW));
  ui->clb_sync->setEnabled(g_pTelePlugin && (g_pTelePlugin->getAttributes() & TPI_CAN_SYNC));
  ui->clb_tracking->setEnabled(obj->type == MO_PLANET ||
                               obj->type == MO_ASTER ||
                               obj->type == MO_COMET ||
                               obj->type == MO_SATELLITE);

  ui->cb_simbad->setDisabled(obj->type == MO_PLANET ||
                             obj->type == MO_ASTER ||
                             obj->type == MO_COMET ||
                             obj->type == MO_PLN_SAT ||
                             obj->type == MO_SATELLITE);

  ui->pushButton_2->setDisabled(obj->type == MO_PLANET ||
                                obj->type == MO_ASTER ||
                                obj->type == MO_COMET ||
                                obj->type == MO_PLN_SAT ||
                                obj->type == MO_SATELLITE);

  ui->pushButton_3->setEnabled(obj->type == MO_ASTER || obj->type == MO_COMET);


  info.fillInfo(view, obj, &m_infoItem);  

  /// read note
  QString str = QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/data/notes/" + m_infoItem.id + ".txt";
  SkFile f(str);
  if (f.open(SkFile::ReadOnly | SkFile::Text))
  {
    ui->textEdit->setPlainText(f.readAll());
    f.close();
  }
  QTextCursor crs(ui->textEdit->textCursor());
  crs.movePosition(QTextCursor::End);
  ui->textEdit->setTextCursor(crs);
  /////////////

  fillInfo(view, &m_infoItem);

  ui->textEdit->setFocus();

  if (m_infoItem.type == MO_PLANET && m_infoItem.par1 != PT_EARTH_SHADOW)
  {
    m_pixmapWidget = new CPixmapWidget();
    ui->gridLayout_5->addWidget(m_pixmapWidget);
    m_pixmapWidget->setPixmap(getPlanetPixmap(m_pixmapWidget->width(), m_pixmapWidget->height()));

    CXMLSimpleMapParser parser;

    parser.begin(readAllFile("../data/planets/" + CAstro::getFileName(m_infoItem.par1) + ".xml"));

    QString str = "<table>\n";

    str += addPhysicalInfo(&parser, "Equator_radius", tr("Equator radius"));
    str += addPhysicalInfo(&parser, "Semi_major_axis", tr("Semi-major axis"));
    str += addPhysicalInfo(&parser, "Eccentricity", tr("Eccentricity"));
    str += addPhysicalInfo(&parser, "Mass", tr("Mass"));
    str += addPhysicalInfo(&parser, "Rotation_period", tr("Rotation period"));
    str += addPhysicalInfo(&parser, "Escape_velocity", tr("Escape velocity"));

    str +=  "</table>\n";

    ui->textBrowser_2->setHtml(str);
  }
  else
  {
    ui->tabWidget->blockSignals(true);
    ui->tabWidget->removeTab(1);
    ui->tabWidget->removeTab(1);
    ui->tabWidget->blockSignals(false);
  }
}