[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] Suggestion2

From: Oscar F
Subject: Re: [lwip-users] Suggestion2
Date: Fri, 31 Jul 2009 07:48:26 +0200

thank you, and another question, ¿with this API, can i receive and send the command? TCP or UDP? and what is your advice about to have one socket open permanent or one socket  for every commmunication?

thanks again

On Fri, Jul 31, 2009 at 7:23 AM, Mathias Zenger <address@hidden> wrote:
To avoid blocking you can use select() to check data reception before calling recvfrom().


(select(FD_SETSIZE, &fd, NULL, NULL, &socket_to)) {

    if (recvfrom(fd_socket, pucRecBuffer, NTP_BUFFER_SIZE, 0, (struct sockaddr *)&addr, &addrlen) >= 0) {




-----Ursprüngliche Nachricht-----
Von: lwip-users-bounces+m.zenger=mobatime.com@nongnu.org [mailto:lwip-users-bounces+m.zenger=mobatime.com@nongnu.org]Im Auftrag von Oscar F
Gesendet: Freitag, 31. Juli 2009 00:16
An: Mailing list for lwIP users
Betreff: [lwip-users] Suggestion2

Hello everybody, i'll have to interchange a lot of command between PC an d my micro of EVK1100 board.

For example the PC send me command to STAR, dates of several tables, ... and the micro has to send too about one second a command to report the situation of the system.

In this board i'll use a lwIP with freeRTOS, and i don know exactly what is the best form to implement the protocol, because always is online with PC.

do you use one socket everytime? or open one socket in every comunication?.   TCP or UDP protocol? the customer say me the port, and is fixed.

Is there any api that not block the process in the recepcion? because i'll have to do three thing:

 case DATE_FROM_PC: 
                                  i'll need to read the date and store in my SDRAM;

                                             i'll do it this command;

case SEND_STATUS_TO_PC: (every second)
                                               i must send a message to report the status of the board;

Can help me this program example:

portTASK_FUNCTION( vBasicTFTPServer, pvParameters )
    int lSocket;
    int lDataLen, lRecvLen;
    socklen_t lFromLen;
    struct sockaddr_in sLocalAddr, sFromAddr;
    portCHAR cData[SEGSIZE+sizeof(struct tftphdr)];
    struct tftphdr *sHdr = (struct tftphdr *)cData;

    // Set up port
    // Network order in info; host order in server:

    for (;;) {
        // Create socket
        lSocket = socket(AF_INET, SOCK_DGRAM, 0);
        if (lSocket < 0) {
        memset((char *)&sLocalAddr, 0, sizeof(sLocalAddr));
        sLocalAddr.sin_family = AF_INET;
        sLocalAddr.sin_len = sizeof(sLocalAddr);
        sLocalAddr.sin_addr.s_addr = htonl(INADDR_ANY);
        sLocalAddr.sin_port = TFTP_PORT;

        if (bind(lSocket, (struct sockaddr *)&sLocalAddr, sizeof(sLocalAddr)) < 0) {
            // Problem setting up my end

        lRecvLen = sizeof(cData);
        lFromLen = sizeof(sFromAddr);
        lDataLen = recvfrom(lSocket, sHdr, lRecvLen, 0,
                            (struct sockaddr *)&sFromAddr, &lFromLen);

        vParTestSetLED( TFTP_LED , pdTRUE );
        close(lSocket); // so that other servers can bind to the TFTP socket

        if ( lDataLen < 0) {

        } else {
            switch (ntohs(sHdr->th_opcode)) {
            case WRQ:
                tftpd_write_file(sHdr, &sFromAddr, lFromLen);
                vParTestSetLED( TFTP_LED , pdFALSE );
            case RRQ:
                tftpd_read_file(sHdr, &sFromAddr, lFromLen);
                vParTestSetLED( TFTP_LED , pdFALSE );
            case ACK:
            case DATA:
            case ERROR:
                vParTestSetLED( TFTP_LED , pdFALSE );
                // Ignore
                  vParTestToggleLED( TFTP_LED );

i don want to block the this task, because in other period i'll have to send a command of status. In this example beyond close the socket and i think,that i need to have always the socket open and bind.

Thank you

lwip-users mailing list

reply via email to

[Prev in Thread] Current Thread [Next in Thread]