📄 myapp.c
字号:
#include "..\uip.h" //LEON.Z.
#include "myapp.h"
#define NULL (void *)0
#ifdef DEBUG
#include <stdio.h>
#define PRINT(x) printf("%s", x)
#define PRINTLN(x) printf("%s\n", x)
#else /* DEBUG */
#define PRINT(x)
#define PRINTLN(x)
#endif /* DEBUG */
struct myapp_state *hs;
#define APPport 1180
/*-----------------------------------------------------------------------------------*/
void
myapp_init(void)
{
/* Listen to port 1180. */
uip_listen(APPport);
}
/*-----------------------------------------------------------------------------------*/
void
myapp(void)
{
// u8_t i;
switch(uip_conn->lport) {
/* This is the web server: */
case htons(APPport):
/* Pick out the application state from the uip_conn structure. */
hs = (struct httpd_state *)(uip_conn->appstate);
if(uip_connected()) {
/* first connect, the app do some initialize here */
//hs->state = HTTP_NOGET;
//hs->count = 0;
/* Don't send any data in return; we wait for the remote request
instead. */
uip_send(uip_appdata, 0);
return;
} else if(uip_poll()) {
/* If we are polled ten times, we abort the connection. This is
because we don't want connections lingering indefinately in
the system. */
if(hs->count++ >= 10) {
uip_abort();
}
return;
} else if(uip_newdata()) {
/* we have recieved the request or data, apply the remote now*/
//--------leon, add the protocal here----, we receive the pc data or
//--retquest, in uip_appdata, length=uip_len;
//and we process it, place our data in uip_appdata. and set uip_len;
/* Check for GET. */
if(uip_appdata[0] != 't' ||
uip_appdata[1] != 'e' ||
uip_appdata[2] != 's' ||
uip_appdata[3] != 't') {
/* If it isn't a GET, we abort the connection. */
uip_abort();
return;
}
uip_appdata[0]='o';
uip_appdata[1]='k';
uip_len=2;
}
if(uip_acked()) {
uip_close();
}
/* Finally, return to uIP. Our outgoing packet will soon be on its
way... */
return;
default:
/* Should never happen. */
uip_abort();
break;
}
}
/*-----------------------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -