Mathias, maybe this code example can be useful.
portTASK_FUNCTION( *vBasicTFTPServer*, pvParameters ){
*int* lSocket;
*struct* sockaddr_in sLocalAddr, sDestAddr;
*char* reply[]="testing";
*char* buffer[1024];
*int* nbytes;
*int* i;
lSocket = lwip_socket(AF_INET, SOCK_DGRAM, 0);
memset((*char* *)&sLocalAddr, 0, *sizeof*(sLocalAddr));
memset((*char* *)&sDestAddr, 0, *sizeof*(sDestAddr));
/*Destination*/
sDestAddr.sin_family = AF_INET;
sDestAddr.sin_len = *sizeof*(sDestAddr);
sDestAddr.sin_addr.s_addr = htonl(INADDR_BROADCAST);
sDestAddr.sin_port = 1234;
/*Source*/
sLocalAddr.sin_family = AF_INET;
sLocalAddr.sin_len = *sizeof*(sLocalAddr);
sLocalAddr.sin_addr.s_addr = htonl(INADDR_ANY);
sLocalAddr.sin_port = 1235;
lwip_bind(lSocket, (*struct* sockaddr *)&sLocalAddr, *sizeof*
(sLocalAddr));
*while* (1) {
nbytes=lwip_recv(lSocket, buffer, *sizeof*(buffer),8);
*if* (nbytes>0){
lwip_sendto(lSocket, buffer, nbytes, 0,
(*struct*sockaddr *)&sDestAddr,
*sizeof*(sDestAddr));
}
lwip_sendto(lSocket, reply, *sizeof*(reply), 0,
(*struct*sockaddr *)&sDestAddr,
*sizeof*(sDestAddr));
vTaskDelay( 200 ); //some delay!
}
lwip_close(lSocket);
}
In my case this could be:
//Open he socket permanent and bind
while(1)
{
- if there is some command received with select API i'll process.
"function to process the command receive"
- if i've to transmit any command i'll send. For example with a semaphore
to wait the interrupt or tick function say me every second pass to send the
next command. "function to process the command to send"
- if i´ve to retransmit any command i´ll send too. "function to process the
command to send again"
-and finally vTaskDelay( 10mseg ); //avoid always enter in this loop
}
//unbind socket and close here and when i had recived the command END.
Is a good solution?
thanks!!!
Oscar
On Fri, Jul 31, 2009 at 8:15 AM, Oscar F <[email protected]> wrote:
> Thanks Mike!, in few days i hope to know what protocol prefer to use the
> customer, i think that will be SDP, because he said me that i've to send ACK
> or NACK for every command.
>
> Regards
> Oscar
>
>
> On Fri, Jul 31, 2009 at 8:07 AM, Mike Kleshov <[email protected]> wrote:
>
>> 2009/7/31 Oscar F <[email protected]>:
>> > 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?
>>
>> The answer to the question 'TCP or UDP' will depend on the
>> requirements of your application. You know them better than anyone on
>> this list.
>> An you know, UDP is basically exchange of datagrams. Those are limited
>> in size and you have to be prepared that occasionally they will not
>> reach their destination. TCP allows you to stream data (no limit on
>> data size) and it gives you reliable transport (retransmissions are
>> handled automatically) but that comes at a cost: TCP code is much more
>> complex and you have almost no control of the retransmission algorithm
>> which can be too slow for some applications.
>>
>> Regards,
>> - mike
>>
>>
>> _______________________________________________
>> lwip-users mailing list
>> [email protected]
>> http://lists.nongnu.org/mailman/listinfo/lwip-users
>>
>
>
_______________________________________________
lwip-users mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/lwip-users