Go Down

Topic: Two concurrent sockets: web server / client (Read 1 time) previous topic - next topic

Swak953

Is there any possibility the Arduino can act as a web server and post data when needed? I've been looking for a working solution in this forum, but the ones I find are working only once (posting data to my server for the first time, but then connection failed).

I'd appreciate any help!

stoutfiles

An easy way is to go to a PHP page with your data in the URL using PHP GET.

www.yourwebsite.com/datacollect.php?data_var=your_data

Swak953

Sorry, maybe I didn't express myself clearly... That's what I'm already doing, but what I'm trying to do is receive http request from a client (acting as a web server) and send http request to another one (acting as a client).

Code: [Select]

//Global variables
GSMServer server(80);
GSMClient client;

void setup(){
server.begin();
GSMClient client = server.available();
  if (client)
  {}
}

//Another function (runs at loop)
client.connect(ext_server, 8080);
 


I tried to create another client (client2) to make client.connect(ext_server, 8080). Have I to stop the server and stop the client (release socket) before trying to make the http request? Has anybody do it or is there another way to?

stoutfiles

Don't believe two simultaneous connections is possible.  Assuming you're passing data from client1 to client2, I would just store the data in a variable (or file on a SD card), drop connection, reestablish new connection, and pass it that way.  I suggest using shutdown() after every connection and waiting at least 5 seconds before starting a new one.

Swak953

What I really need is to make HTTP requests to a server (posting data) every time I programm, and listening to HTTP requests when nothing has to be sent. This means the board is continuosly listening to a web client and, when the timer expires, sends readings to a server.

stoutfiles

Would need a lot more information to justify why you'd want to continuously listen, and not use an Ethernet and/or Wifi shield for this task.

Go Up