You can chat about native SDK questions and issues here.

User avatar
By kript0n
#63441 I am writing simple server and esp documentation says that I can not use espconn which is passed to connect callback, to distinguish different connections.

Image

Imagine that I have several tcp clients that connected to my server and I want to send data to a certain one. How can I do that if I am not able to save pointer to each of them?
User avatar
By Mitchell QTT
#65069 That pointer points to an object which might be removed.

Example: http://bbs.espressif.com/viewtopic.php?t=3369
Here you can see that for every connect-event, a receive- and a disconnect-function are registered.
You should probably follow the object back to an IP and port; these will uniquely identify a remote host.

It is good practice if the server only responds, so it does not intiate data-messages.
If you can write your server in such a fashion, that would lead to a clean client-server model.
In the receive-function you respond to a clients request, and then you forget all about it. Stateless.

In such a model the client sometimes polles to see if there's any data for him - so the initiative is Always with the client.

Ok, suppose you DO want to initiate data from the server.
In the connect event you get handed an object-pointer which can identify the connection.

I think you need to copy that object, or duplicate its data in your own espconn-struct, so you can call:
void espconn_sent(struct espconn *espconn, uint8 *psent, uint16 length);

So when you get the connection-callback, remember the data (preferably in a struct), and use that when you need to send data.