question on "write" (send) function

davdav
Posts: 208
Joined: Thu Nov 17, 2016 2:33 pm

question on "write" (send) function

Postby davdav » Mon Nov 28, 2016 11:40 am

Hi everybody,
I'm trying to send some data to a server using function "write" ("send"). In particular I receive data string from uart0 and then I send to the server.

The server waits for a EOL (in my case I send a '\n' at the end of the string) in order to parse the received string.

I noted a problem for my application: the write (or send) function adds an EOL to the end of the data string. In pratice if I send just one character, then the server receive also a EOL.This is not how it should work.

For example if I emulate the same using Putty (as a TCP client) until I send a "\n" or "\r" the server doesn't parse the string, while using the "write" or "send" function it does.

I have tried to explore the lwip components folder and some of its file (sockets.c, api_lib.c..) but I can't find where an EOL is attached.

Is it possible to avoid this?

Thank you.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: question on "write" (send) function

Postby kolban » Mon Nov 28, 2016 3:32 pm

Howdy, in my own mind, it is 99.9% certain that if your server is receiving a '\n' character through the socket then you are actually sending a '\n' character from the client. Check the following:

1) Dump the buffer you are sending, look at the end of the data ... if you find a newline, there is your issue.
2) Dump the buffer you are receiving, make sure you only dump the length of data received, since at this point you know you are not sending a newline, validate that there is in fact no newline in the received data. If there is, go back to 1.
3) At his point we have validated that there is no newline being transmitted and actually no newline being received ... now is the time to question the original assumption about there being a newline being present in the transmitted data.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

Who is online

Users browsing this forum: Baidu [Spider] and 121 guests