'server' was not declared in this scope, ethernet webserver

I’m having trouble with initiating my http-webserver for a connection between my app and arduino.
I use a W5100 ethernet shield and okhttp to transfer the data, but it keeps giving me this error:
’server’ was not declared in this scope

Here’s my code (This is in a seperated class, not the main algoritme):

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

byte mac = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(192, 168, 1, 177);

void setup()
EthernetServer server(80);


// Open serial communications

// start the Ethernet connection and the server
Ethernet.begin(mac, ip);

void loop() {
// Is there a client (Our Android smartphone)
EthernetClient client = server.available();
if (client) {
// Let’s start reading
boolean isLastLine = true;
boolean isBody = false;
header = “”;
reqData = “”;
int contentLen = 0;

Serial.print(“Client connected!”);
while (client.connected()) {
if (client.available()) {
// Read data
char c = client.read();

if (contentSize == contentLen) {
Serial.println(“Body [”+reqData+"]");
// Extract the JSON string like [r,g,b]
int pos1 = reqData.indexOf("[");
int pos2 = reqData.lastIndexOf("]");

// Parse the string looking for ,
String data = reqData.substring(pos1 + 1, pos2);
int idx1 = data.indexOf(’,’);
int idx2 = data.indexOf(’,’, idx1+1);
int idx3 = data.indexOf(’,’, idx2+1);
String stringSlider = data.substring(0, idx1);
String ??? = data.substring(idx1 + 1, idx2);
String ??? = data.substring(idx2 + 1, idx3);

// Zet string om naar intiger
int slider = stringSlider.toInt();
int ??? = ???.toInt();
int ??? = ???.toInt();

// Create the response to client
client.println(“HTTP/1.1 200 OK”);
client.println(“Content-Type: text/html”);
client.println(“Connection: close”);
// send web page
client.println(""); delay(1);

if (c == ‘\n’ &amp;amp;amp;&amp;amp;amp; isLastLine) {
isBody = true;
int pos = header.indexOf(CONTENT_LENGTH_TXT);
String tmp = header.substring(pos, header.length());
//Serial.println(“Tmp [”+tmp+"]");
int pos1 = tmp.indexOf("\r\n");
String size = tmp.substring(CONTENT_LENGTH_TXT.length(), pos1);
Serial.println(“Size [”+size+"]");
contentSize = size.toInt();

if (isBody) {
reqData += c;
else {
header += c;

if (c == ‘\n’ ) {
isLastLine = true;
else if (c != ‘\r’ ) {
isLastLine = false;


// Close connection

server is only in scope inside setup.

You've defined server in setup(), so it is local to that routine. It cannot be seen in loop()

You've defined server in setup(), so it is local to that routine. It cannot be seen in loop()

More to the point its destructor is called and its memory reclaimed when setup() exits, not just out of scope.

Global objects need to be declared at top level. The init() call belongs in setup still.

Thanks, seems it wasn't the only constant that didn't work.