I've a program where I can start matlab on a server where the ip-address and port no's are the inputs.As of now,these inputs are hard-coded in the code.When the IP-address matched with that of my local machine, then this works fine.I'm kinda confused in order to modify this code to make it working on a different machine.Could somebody pls help me. Thanks for your time.
Heres the code under the action event if (event.getActionCommand().equals(StartRC)){ MatlabRCSocket = new Socket("IP-address",7777); in = new DataInputStream(MatlabRCSocket.getInputStream()); out = new DataOutputStream(MatlabRCSocket.getOutputStream()); System.out.println(in.readUTF()); remote = true; command.setText(""); startRC.setEnabled(false); stopRC.setEnabled(true); return; } if (event.getActionCommand().equals(StopRC)){ in.close(); out.close(); MatlabRCSocket.close(); System.out.println("Connection ended"); remote = false; startRC.setEnabled(true); stopRC.setEnabled(false); return; }
and the class file looks like class MatlabRCServer extends Thread { private MatEng engine; DataInputStream in; DataOutputStream out; Socket MatlabRCSocket; ServerSocket MatlabRCServerSocket;
public MatlabRCServer() { try { MatlabRCServerSocket = new ServerSocket(7777); } catch (IOException e) { System.out.println("ServerSocket-Error" + e.getMessage()); } }
public void run () { while (true) { try {
MatlabRCSocket = MatlabRCServerSocket.accept();
in = new DataInputStream(MatlabRCSocket.getInputStream()); out = new DataOutputStream(MatlabRCSocket.getOutputStream());
In order to connect to the other machine u dont have to do the extra coding. Just give the address of the remote machine and the port number in the socket constructor. Only thing is that server has to be present on the network.