Hi hugueslarrive
Thanks for your input, in my main programm I changed the stacksize to 4096, but had still the same error.
I tried it now in the test programm, still the same Issue.
LWIP_DBG_ON didnt print anything neither…
This is my code I added to the _tcp_recv function to get the minimum Communication with my frontend:
#define HTTP_MESSAGE_BUFF_SIZE (10*SOCK_INBUF_SIZE)
static int emptyCstring(char *dest, size_t element_count){
int answer = EXIT_SUCCESS;
memset(dest,0,element_count);
if(strlen(dest)>0){
answer = EXIT_FAILURE;
}
return answer;
}
static int getHttpMethod(char *src, char *http_method_str){
return sscanf(src, "%7s", http_method_str);
}
static int getHttpOrigin(char *src, char *http_origin_str){
char * origin_place = strstr(src, "Origin");
return sscanf(origin_place+strlen("Origin:"), "%256s", http_origin_str);
}
static int getHttpMethodAndOrigin(char *src, char *http_method_str, char *http_origin_str){
/* Parse the HTTP request */
int status = EXIT_SUCCESS;
int n = getHttpMethod(src, http_method_str);
n += getHttpOrigin(src, http_origin_str);
if (n != 2) {
status = EXIT_FAILURE;
}
return status;
}
static void _tcp_recv(sock_tcp_t *sock, sock_async_flags_t flags, void *arg)
{
sock_tcp_ep_t client;
uint16_t port;
printf("\n\n************** the flag is 0x%04x **************\n\n",flags);
expect(strcmp(arg, "test") == 0);
if (sock_tcp_get_remote(sock, &client) < 0) {
/* socket was disconnected between event firing and this handler */
return;
}
sock_tcp_ep_fmt(&client, _addr_str, &port);
if (flags & SOCK_ASYNC_MSG_RECV) {
static char http_message[HTTP_MESSAGE_BUFF_SIZE];
char method[8];
char origin[256];
int res;
emptyCstring(method,8);
emptyCstring(origin,256);
emptyCstring(http_message,HTTP_MESSAGE_BUFF_SIZE);
emptyCstring(sock_inbuf,SOCK_INBUF_SIZE);
/* we don't use timeouts so all errors should be related to a lost
* connection */
puts(http_message);
while (((res = sock_tcp_read(sock, sock_inbuf, sizeof(sock_inbuf),
50)) >= 0)) {
printf("Received TCP data from client [%s]:%u\n", _addr_str, port);
if (res > 0) {
printf("\nNumber of bytes arrived: %d\n\n",res);
strncat(http_message,sock_inbuf,SOCK_INBUF_SIZE);
emptyCstring(sock_inbuf,SOCK_INBUF_SIZE);
if(res<SOCK_INBUF_SIZE){
break;
}
}
else {
puts("(nul)");
}
}
printf("\nthe flag is 0x%04x\n\n",flags);
printf("\nthe number of res is %d\n\n",res);
getHttpMethodAndOrigin(http_message,method,origin);
puts(http_message);
puts(method);
if(strncmp(method,"OPTIONS",strlen("OPTIONS"))==0){
puts("enterd options");
char *message="HTTP/1.0 200 OK\r\nAccess-Control-Allow-Headers: authorization, content-type, timeout\r\nAccess-Control-Allow-Methods: DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT\r\nAccess-Control-Allow-Origin: http://localhost:8081\r\nAllow: OPTIONS, POST\r\nContent-Length: 0\r\nContent-Type: text/html; charset=utf-8\r\nVary: Origin\r\n\r\n";
sock_tcp_write(sock,message,strlen(message));
}else if(strncmp(method,"POST",strlen("POST"))==0){
puts("enterd POST");
char *message2="HTTP/1.0 200 OK\r\nAccess-Control-Allow-Origin: http://localhost:8081\r\nContent-Length: 58\r\nContent-Type: application/json\r\nVary: Origin\r\n\r\n{\"id\":\"1\",\"jsonrpc\":\"2.0\",\"result\": \"{\\\"status\\\":\\\"OK\\\"}\"}";
sock_tcp_write(sock,message2,strlen(message2));
puts("message sent");
}
}
if (flags & SOCK_ASYNC_CONN_FIN) {
printf("TCP connection to [%s]:%u reset\n", _addr_str, port);
sock_tcp_disconnect(sock);
}
}