Webserver and web client at the same time? Only getting the server.

What I’m trying to achieve is to get an Arduino Uno with Ethernet shield and LCD to run s aserver which I can send messages to and they get displayed on the LCD (This part is working) and also have a client from the arduino connect to a different server to upload some values.

I have half the code working - in as much as I can send messages to the Arduino. But my code never seems to get to the part where it sends this HTTP request.

The code is a very-much-in-progress mess at the moment, so I do apologise for that. The client connection should start at line 102 and the server starts at line 145, and that bit is currently working.

I have looked at the example code for a server and client at the same time, and can’t see what’s different about my code that’s preventing it from running as expected. Presumably what I’m trying to achieve is actually possible? Thanks so much for any help!

#include <SPI.h>
#include <Ethernet.h>
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 2, 4, 5, 6);

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 0, 75 }; // arduino server ip in lan
byte gateway[] = { 192, 168, 0, 33 }; // internet access via router gateway
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
char server2[] = "";   

EthernetServer server(80); //arduino server port
EthernetClient client;

String readString; 

#define aref_voltage 3.3         // we tie 3.3V to ARef and measure it with a multimeter!

//TMP36 Pin Variables
int tempPin = A1;        //the analog pin the TMP36's Vout (sense) pin is connected to
int tempReading;        // the analog reading from the sensor

//ldr pin
int LDR_Pin = A2; //analog pin 0

unsigned long lastConnectionTime = 0;          // last time you connected to the server, in milliseconds
boolean lastConnected = false;                 // state of the connection last time through the main loop
const unsigned long postingInterval = 60*1000;  // delay between updates, in milliseconds

void setup(){

///notification LED
pinMode(9, OUTPUT);

  //for 3.3v for tmp36
  lcd.begin(16, 2);
  // Print a message to the LCD.
 digitalWrite(9, HIGH);
  lcd.print("      SEM");
  //line 2
  lcd.setCursor(0, 1);
  lcd.print("     v0.9.1");
  //start Ethernet
  Ethernet.begin(mac, ip, gateway, subnet);
  digitalWrite(9, LOW);
  lcd.setCursor(0, 1);
  Serial.println("Setup good!");

void loop(){

  //top line of constant text
      lcd.setCursor(0, 0);
      lcd.println(" Soundwell Home ");
  //reading light value
  int LDRReading = analogRead(LDR_Pin); 
      lcd.setCursor(0, 1);
  ///starting temperature  
  tempReading = analogRead(tempPin);  

  float voltage = tempReading * aref_voltage;
  voltage /= 1024.0; 
  // now print out the temperature
  float temperatureC = (voltage - 0.5) * 100 ;  //converting from 10 mv per degree wit 500 mV offset
  lcd.setCursor(8, 1);
  lcd.print((char)223); //degree symbol
///finished temperature


  //sensor upload
  // if there's no net connection, but there was one last time
  // through the loop, then stop the client:
  if (!client.connected() && lastConnected) {

  // if you're not connected, and ten seconds have passed since
  // your last connection, then connect again and send data:
  if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
     // if there's a successful connection:
  if (client.connect(server2, 8033)) {
    // send the HTTP PUT request:
    client.print("GET /soundwellhome/tempwrite.php?=");
    client.println(" HTTP/1.1");
    //client.println("Host: www.google.com");
    client.println("Connection: close");

    // note the time that the connection was made:
    lastConnectionTime = millis();
  else {
    // if you couldn't make a connection:
    Serial.println("connection failed");
  // store the state of the connection for next time through
  // the loop:
  lastConnected = client.connected();

//wait for message uploads
  // Create a client connection
  Serial.println("Starting webserver...");
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        Serial.println("Client connected!");
     char c = client.read();

        //read char by char HTTP request
        if (readString.length() < 100) {

          //store characters to string 
          readString += c; 

        //if HTTP request has ended
        if (c == '\n') {

         Serial.println("Client disconnected!");
          //stopping client
    //line 1
    lcd.setCursor(0, 0);
      if (readString.indexOf("?m=") >0){
        digitalWrite(9, HIGH);
      readString.replace("GET /?m=", "");
      readString.replace(" HTTP/1.1", "");

      if (readString.indexOf("?m2=") >0){
        digitalWrite(9, HIGH);
    lcd.setCursor(0, 1);
        readString.replace("GET /?m2=", "");
      readString.replace(" HTTP/1.1", "");

delay (3000);
digitalWrite(9, LOW);
        //clearing string for next read

  }//client connection ended


First, you are missing a parameter to the Ethernet.begin() call.

  // change this
  Ethernet.begin(mac, ip, gateway, subnet);
  // to this
  Ethernet.begin(mac, ip, gateway, gateway, subnet);


Second, are you certain the server is listening on port 8033?

  if (client.connect(server2, 8033)) {

Most listen on port 80.

Third, what are the messages on the serial monitor?

edit: And you should connect using an IPAddress rather than a character array.

// change this
char server2[] = ""; 
// to this
IPAddress server2(192,168,0,105);