Creating multiple ethernet tcp servers as an array of sockets

Hello All,

I am using UIPEthernet library on enc28J60 on Arduino UNO. The code connecting a single server socket connection listening to single TCP client is working fine.

I wish to create 4 identical server objects listening to 4 identical clients - each with a different port number.

I wish to create an array of servers as follows:

EthernetServer server[0] = EthernetServer(port_num+0);
EthernetServer server[1] = EthernetServer(port_num+1);
EthernetServer server[2] = EthernetServer(port_num+2);
EthernetServer server[3] = EthernetServer(port_num+3);

When I compile this statement, I get an error as follows:

Tcp_Multi_Server_array.ino:48:24: error: conflicting declaration 'UIPServer server [1]'
Tcp_Multi_Server_array.ino:47:16: error: 'server' has a previous declaration as 'UIPServer server [0]'

It seems that library does not allow a subscripted variable as an object name. If yes then, is there a work around?

I wish I could do the instantiation of server inside a for loop in setup()!!
Thanks in advance.

It seems that library does not allow a subscripted variable as an object name.

A subscript on a variable name indicates that the variable is an array. You are trying to create 4 arrays with the same name.

You need to declare that server is an array with 4 elements, and populate each one.

EthernetServer server[4] = { EthernetServer(port_num+0),
EthernetServer(port_num+1),
EthernetServer(port_num+2),
EthernetServer(port_num+3) };

Good luck doing that with an ENC28J60.