Simple examples of web servers in UIP

Source: Internet
Author: User
Tags htons

This is an example code in the official document to learn how UIP processes Web servers.

Struct example5_state {char * dataptr; unsigned int dataleft;} void example5_init (void) {uip_listen (htons (80); values (htons (81);} void example5_app (void) {struct example5_state * s; S = (struct example5_state) uip_conn-> appstate; If (uip_connected () {Switch (uip_conn-> lport) {Case htons (80 ): s-> dataptr = data_port_80; s-> dataleft = datalen_port_80; break; Case htons (81): S-> dataptr = data_port_81; s-> dataleft = break ;} uip_send (S-> dataptr, S-> dataleft); return;} If (uip_acked () {If (S-> dateleft <uip_mss () {uip_close (); return;} s-> dataptr + = uip_conn-> Len; s-> dataleft-= uip_conn-> Len; uip_send (S-> dataptr, S-> dataleft );}

The struct contains the address and length of the file to be sent. The initialization function listens to ports 80 and 81 respectively. The app function processes different connections based on the port value. This app responds to the drive uip_asked (). If the length of the file to be sent is smaller than the length returned by uip_mss (), it means that the file has been sent and uip_close () is executed (). If no, adjust the file pointer and length information and continue sending through uip_send.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.