TCP Server
TCP Server
h"
#include "lwip/tcp.h"
#include "string.h"
#include "stdio.h"
return ERR_OK;
}
static err_t tcp_server_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t
err) {
if (p != NULL) {
// Acknowledge that we've received the data
tcp_recved(tpcb, p->tot_len);
char received_message[256];
if (p->len < sizeof(received_message)) {
memcpy(received_message, p->payload, p->len);
received_message[p->len] = '\0'; // Null-terminate the string
printf("Message: %s\n", received_message);
}
// Prepare a response
const char *response = "Hello from STM32 TCP server!";
tcp_write(tpcb, response, strlen(response), TCP_WRITE_FLAG_COPY);
return ERR_OK;
}
void tcp_server_init(void) {
struct tcp_pcb *pcb;
int main(void) {
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_LWIP_Init();