Ethernet2 and two ports

Any code on how to set up two ports using an ethernet2 shield on a Mega 256.

I an trying to read data from an 'instrument' on port 1001 using simple telnet, and map and store these as Modbus variables. I then need to poll the stored variables from the Modbus registers on port 502.

So both ports will be open all the time,

Any ideas or suggestions, thanks.

What have you tried so far? Have you written any code at all? The Telnet client example sets up an EthernetClient object and updates it in loop(). The example shows how to specify the port. Presumably, you should be able to merge it with another connection (but you didn't specify the modbus TCP/IP connection type...). Then you just update that in loop() as well.

The library advertises that it can handle up to four connections, so that part should work.

Thanks for reply.

I am using the Modbus Arduino TCP/IP driver, and I have modified the telnet driver to become a functional driver, however they are in sperate scripts, although a bit rough at the moment, as I am just trying to knit things together. I have also got the network and parameters reading from a SD card, so I do not have to keep doing hard code changes for network etc. So this is the last jigsaw bit is the puzzle, before tying it all together..

The telnet code calls the Ethernet instance as per documented, as does the Modbus , however this calls it from its own script, this might need changing so the are together and making it easier to follow at a later date.

I purchased the Ethernet2 shield as it has got references to four ports, but no real documentation.

One port will be sequential, or within the main loop, getting values and storing them within the Modbus structure, but the the other will be an inbound event as and when. I had thought about opening two ports and checking for inbound before restarting the main loop., or can I use an interrupt? Either way do I open two instances of the server ports? I will need to set up a test rig with wireshark and see what packets are being processed.

But there is no real data on this, or do you take it is as being identical, but just four ports.

Any idea?