Example #1
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    //set initial position
    QDesktopWidget *desk=QApplication::desktop();
    move((desk->width()-width())*6/7,(desk->height()-height())/2);

    stdModel = new QStandardItemModel();

    winList.empty();
    buildConnection();
}
int main(int argc,char **argv)
{
     if(argc<2)
     {
          printf("usage: a IP \n");
          exit(0);
     }

     char *addr=argv[1];
     int port=PORT;
     int sockfd,n;
     sockfd=buildConnection( addr,port );
     while(1)
     {
          printf("waiting for input or network\n");
          clientReadWrite(sockfd);
     }


}
Example #3
0
int main()
{

     printf("start server\n");
     int sockfd,connfd,n;
     pid_t pid;
     sockfd=buildConnection(PORT);
     char  rec[MAX],send[MAX];
     while(true)
     {
          connfd=accept(sockfd,NULL,NULL);
              
	  echo(connfd);
         /* if((pid=fork())==0)
          {
               close(sockfd);
               echo(connfd);
          }
          close(connfd);
	  */
     }
     close(sockfd);

}     
Example #4
0
/*-----------------------------------------------------------------------------
 * cntProcessPacket()
 *---------------------------------------------------------------------------*/
struct connection *	cntProcessPacket( struct packet *p )
{
    int    i;
    int    connectionIdx;
    uchar  bFound;

    assert( p != NULL );

    /* comprobamos si es un paquete de una conexión que ya procesamos */
    bFound = FALSE;
    for( i = 0; i < MAX_CONNECTIONS  &&  bFound == FALSE; i++ )
    {
        /* comprobamos que el par origen-destino coincide */
        if( belongToConnection( &(connections[i].c), p ) == TRUE )
        {
            connectionIdx = i;
            bFound        = TRUE;
        }
    }

    /* si ya existe, lo contabilizamos en las estadísticas */
    if( bFound == TRUE )
    {
        /* calculamos estadísticas */
        computeStatistics( &connections[connectionIdx], p );

        /* devolvemos la conexción asociada */
        return  &(connections[connectionIdx].c);
    }
    /* si no pertenece a ninguno */
    else
    {
        /* buscamos el primer slot libre */
        for( i = 0; i < MAX_CONNECTIONS && bFound == FALSE; i++ )
        {
            if( connections[i].free == TRUE )
            {
                connectionIdx = i;
                bFound        = TRUE;
            }
        }

        if( bFound == TRUE )
        {
            /* creamos una nueva conexión */
            if( buildConnection( &connections[connectionIdx], p ) == TRUE )
            {
                /* contabilizamos las primeras estadísticas */
                computeStatistics( &connections[connectionIdx], p );

                /* devolvemos la conexción asociada */
                return  &(connections[connectionIdx].c);
            }
            else
            {
                return  NULL;
            }
        }
        else
        {
            /* no tenemos espacio libre para procesar más conexiones */
            return  NULL;
        }
    }
}