I’ll be asking a question about communication between Sparks and Local Server.
Whenever a Spark Core connects to wifi, It should also connect to Local Server and keep connection open to get commands. I have a basic connection algorithm for that.
1) Local Server listens 1111 as UDP server (I'm still not sure how to do that) 2) Spark broadcasts it's IP with UDP to *.*.*.255 3) After LS gets the datagram, sends a available port number X to sender Spark with Udp on port 2222 and listens port X for incoming Tcp connection. 4) After Spark gets the datagram includes port number X, Spark connects to LS on port X with TCP 5) After TCP connection is established, Spark sends its deviceId and wait for commands.
With this algorithm, because I’m not sure how to use a server in C++, I’m having trouble to implement it. But I have other one in which I use Spark as server and LS connects to it.
1) Local Server listens 1111 as UDP server (I'm still not sure how to do that) 2) Spark listens port X for TCP connection 2) Spark broadcasts it's IP and port X with Udp to *.*.*.255 3) After LS gets the datagram, LS creates a client socket and connects to Spark's X port 5) After TCP connection established, Spark sends its deviceId and wait for commands.
Note: There is one Local Server and many Spark Cores connect to it. Then I think Local Server must behave like a server.
I hope I express myself clearly. Please help me to decide what to do.
Thanks a lot.