Re: communication between 2 socket
What is a "PLC" system?
It's a Programmable logic controller used to control machines.
The PLC is a client that connects to port 5000 of a given IP, so I have to
write a server that handles the communication.
However, I have multiple clients on PCs which have to connect to PLC server,
sending commands and receiving answers.
Ok. So what you are essentially doing is creating a "proxy" server to sit
between the client PCs and the PLC. The proxy will communicate with the PLC on
port 5000. It needs to receive commands from clients, forward them to the PLC,
get responses from the PLC and relay those back to the clients. Is that about
the size of it?
I don't see any reason why an RMI server could not handle that. The main problem
you have is that, although the RMI server can handle multiple clients
simultaneously by being multi-threaded, the communication with the PLC may need
to be single-threaded. If so, that would require synchronizing use of the
Socket which is used for this communication. Do you know if the PLC can handle
multiple connections simultaneously? If it can you can create one Socket per
client in the RMI service call, or maybe a pool of Sockets if speed is
important and creating and tearing down sockets is too slow or expensive in
resources on the the PLC. Otherwise you will need to create a single Socket and
use that in each service call, making sure to synchronize use of this Socket to
prevent multiple threads from using it at the same time.
I'd start out simple, with an RMI interface which supports just a single command
with a simple response (if the PLC command set includes one). Program that
interface and implement it in the RMI server. Build a simple RMI client which
makes a request of the RMI server via the RMI interface and test that the
communication between RMI client->RMI server->PLC server and back again is
working. Then I'd try multiple clients to check concurrency, put a delay in the
RMI server response if necessary to ensure both clients are making RMI requests
at the same time. This will verify that multi-threading in the RMI server is
Build up from this simple base to add the entire PLC command set.
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : firstname.lastname@example.org
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555