I have several ESP32 DevkitC boards that are to be interconnected using TCP sockets with no HTTP involved. One of these boards is nominated the Master/server and the others are all Station/clients. They all connect via the same Access Point using fixed IP numbers. So far so good.
The Master/server operates a port called Cport that is dedicated to receiving incoming connection requests from various Station/clients, as per normal. I am able to accept() connection requests and establish working sockets and to transfer data. So what is the problem you might ask?
One problem I had was about recognising which Station was ‘requesting to connect’ and I have solved that problem by passing a sockaddr struct to the accept() function. From that sockaddr struct I can see the fixed IP of the incoming requestor. So that works well to identify the requesting Station/client.
But I still have a problem because some of the Station boards require more than one socket connection to handle more than one service from the Master/server. So my hope was that if I could set the localPort() value of the requesting Station before I issued the connect() request then the sockaddr data coming back to the Master/server from the accept() call would include the requestors localPort as well as its localIP. In that way I would know not only which Station was calling but also what Service that they were requesting.And that would solve my issue nicely.
Of course I could use the socket returned by accept() to communicate with the calling Station to find out which service it requires. That now looks to be the logical way to go, but the docs do say that the accept() function will return the requestor’s localIP and its localPort so that should be doable too. If I only I knew how.
TIA for all replies.
You are programming your boards using MicroPython, right?
Which documentation are you referring to? And what examples are you following?
No I am programming in C/C++ not Micro Python. Thanks for your answer but it is all a bit irrelevant because I have moved my comms to ESP-NOW and think that can achieve my data transfer needs in a much simpler way. I will close this question now. Thanks.