void uip_appcall(void)
{
uint8_t send = 0;
uint16_t a, b;
if (ntohs(uip_conn->lport) == 8000)
{
if (uip_connected())
{
uip_conn->appstate.step = 0;
send = 1;
sprintf(uip_conn->appstate.buf, "Connected! id=%d, port=%d\n", uip_conn - uip_conns, ntohs(uip_conn->lport)); // 顯示所用的conn連接數組下標號, 以及端口號
}
if (uip_rexmit())
send = 1;
if (uip_newdata())
{
uip_conn->appstate.step++;
send = 1;
if (uip_conn->appstate.step == 1)
{
((char *)uip_appdata)[uip_len] = '\0';
sscanf(uip_appdata, "%d, %d", &a, &b);
sprintf(uip_conn->appstate.buf, "sum=%d\n", a + b);
}
}
if (send)
{
switch (uip_conn->appstate.step)
{
case 0:
case 1:
uip_send(uip_conn->appstate.buf, strlen(uip_conn->appstate.buf));
break;
case 2:
uip_send_P(PSTR("Ignored!\n"));
break;
}
}
}
else if (ntohs(uip_conn->lport) == 3000)
{
if (uip_connected())
{
uip_conn->appstate.step = 0;
send = 1;
}
if (uip_rexmit())
send = 1;
if (uip_acked())
{
send = 1;
uip_conn->appstate.step++;
}
if (send)
{
switch (uip_conn->appstate.step)
{
case 0:
uip_send_P(PSTR("The closesocket function closes a socket. Use it to release the socket descriptor passed in the s parameter. Note that the socket descriptor passed in the s parameter may immediately be reused by the system as soon as closesocket function is issued. "));
break;
case 1:
uip_send_P(PSTR("As a result, it is not reliable to expect further references to the socket descriptor passed in the s parameter to fail with the error WSAENOTSOCK. A Winsock client must never issue closesocket on s concurrently with another Winsock function call.\n"));
break;
case 2:
uip_send_P(PSTR("Any pending overlapped send and receive operations ( WSASend/ WSASendTo/ WSARecv/ WSARecvFrom with an overlapped socket) issued by any thread in this process are also canceled. "));
break;
case 3:
uip_send_P(PSTR("Any event, completion routine, or completion port action specified for these overlapped operations is performed. The pending overlapped operations fail with the error status WSA_OPERATION_ABORTED.\n"));
break;
case 4:
uip_send_P(PSTR("An application should not assume that any outstanding I/O operations on a socket will all be guaranteed to completed when closesocket returns. "));
break;
case 5:
uip_send_P(PSTR("The closesocket function will initiate cancellation on the outstanding I/O operations, but that does not mean that an application will receive I/O completion for these I/O operations by the time the closesocket function returns. "));
break;
case 6:
uip_send_P(PSTR("Thus, an application should not cleanup any resources (WSAOVERLAPPED structures, for example) referenced by the outstanding I/O requests until the I/O requests are indeed completed.\n"));
break;
case 7:
uip_send_P(PSTR("An application should always have a matching call to closesocket for each successful call to socket to return any socket resources to the system.\n"));
break;
case 8:
uip_send_P(PSTR("The linger structure maintains information about a specific socket that specifies how that socket should behave when data is queued to be sent and the closesocket function is called on the socket.\n"));
break;
case 9:
uip_send_P(PSTR("The l_onoff member of the linger structure determines whether a socket should remain open for a specified amount of time after a closesocket function call to enable queued data to be sent. This member can be modified in two ways.\n"));
break;
}
}
}
}
void uip_udp_appcall(void)
{
}
void myapp_init(void)
{
uip_listen(HTONS(3000));
uip_listen(HTONS(8000));
}